describe('test/app/controller/home.test.js', () => { it('should assert', function* () { 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); }); });
it('should invoke API without argument', async () => { const {time} = await request({ method: 'GET', url: `${server.info.uri}/api/sample/ping`, json: true }) assert(typeof time === 'string') })
describe('typescript.test.ts', () => { it('should success', () => { const obj = require('./sub'); console.log('###', obj.default.name); assert(obj.default.name === 'egg from ts'); }); it('should fail', () => { const obj = require('./sub'); console.log('###', obj.default.name); assert(obj.default.name === 'wrong assert ts'); }); });
describe('hooks', () => { it('test', async () => { const hooks = new Hooks() const s = {} hooks.tap('test', (c) => { c.a = 1 }) // eslint-disable-line await hooks.call('test', s) assert(s.a === 1) await hooks.call('x', s) assert(s.a === 1) expect(() => hooks.tap('test', () => null)).toThrow('Hook `test` exists') }) })
// import * as assert from 'assert'; describe('test/index.test.ts', () => { // placeholder comments it('should throw error', async () => { throw new Error('error'); }); // placeholder comments it('should assert', async () => { const obj = { key: '111' }; assert(obj.key === '222'); }); });
describe('#fn.len()', function () { it(`fn.len(obj) should return length of the obj.`, function () { const obj1 = { name: 'Tom' }; const obj2 = ['hello!']; const obj3 = (a, b) => { }; assert(fn.len(obj1) === 1, fn.len(obj2) === 1, fn.len(obj3) === 2); }); });
describe('#fn.contains()', function () { var persons = [{ name: 'Tom', age: 22 }, { name: 'Jerry', age: 18 }]; it(`fn.contains(persons, {name: 'Tom'}) should return is Tom in persons.`, function () { assert(fn.contains(persons, { name: 'Tom' })); }); it(`fn.contains(persons, ps => ps.name === 'Tom') should return is Tom in persons.`, function () { assert(fn.contains(persons, ps => ps.name === 'Tom')); }); it(`fn.contains(persons, ps => ps.name === 'Tom') should return is Tom in persons.`, function () { assert(fn.contains(['Tom', 'Jerry', 'Marry'], 'Tom')); }); });
describe('power-assert-fail.js', () => { it('should fail', () => { assert(1 === 2); }); });
describe('test/app/controller/home.test.js', () => { it('should assert', function* () { 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); }); });
it('should invoke async API with argument', async () => { const greetings = await request({ method: 'POST', url: `${server.info.uri}/api/sample/greeting`, body: { name: 'John' }, json: true }) assert(greetings === 'Hello John !') })