# shaozi-api-test **Repository Path**: cwfan/shaozi-api-test ## Basic Information - **Project Name**: shaozi-api-test - **Description**: 用来给哨子的api做测试的代码 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2016-04-07 - **Last Updated**: 2024-03-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #shao api test ##说明 在test文件夹中按功能分别存放测试文件,并且在index.js中分别引用 使用之前要先安装`mocha` ``` npm install -g mocha ``` 编写完测试代码之后可以通过`npm test`检查测试结果 使用到 [superagent](http://visionmedia.github.io/superagent/) [expect](http://chaijs.com/api/bdd/) [mocha](http://mochajs.org/) 范例: ###tag.test.js ```javascript const request = require('../request').request, expect = require('chai').expect;; describe('/Tag/Rule test', function() { it('/Tag/Rule with empty token shoud success', function(done) { request({ token: "", url: "/Tag/Rule" }) .end(function(e, res) { expect(e).to.eql(null) expect(res.body).to.be.an('object'); expect(res.body.code).to.equal(403); expect(res.body.msg).to.be.a('string'); done() }) }) }); ``` ###require in index.js ```javascript describe('Shaozi DEV.API Server', function() { require('./test/tag.test.js'); require('./test/xxx.test.js'); //... }); ```