测试文件,统一以 *.test.js结尾
home.test.js
'use strict';
const { app, assert } = require('egg-mock/bootstrap');
describe('test/app/controller/home.test.js', () => {
it('should assert', () => {
const pkg = require('../../../package.json');
assert(app.config.keys.startsWith(pkg.name));
// const ctx = app.mockContext({});
// yield ctx.service.xx();
});
it('should GET /', () => {
return app.httpRequest()
.get('/')
.expect('hi, egg')
.expect(200);
});
});
user.test.js
'use strict';
const { app } = require('egg-mock/bootstrap');
describe('user test', () => {
it('test/app/controller/user.test.js', () => {
return app.httpRequest()
.get('/user')
.expect(200)
.expect('user controller index');
});
it('test/app/controller/user.test.js', async () => {
await app.httpRequest()
.get('/user/lists')
.expect(200)
.expect('[{"id":1,"name":"lucy"}]'); // 严格的JSON
});
});