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('findOne returns a Query', function() { // query assert.ok(BlogPostB.findOne({}) instanceof Query); // query, fields assert.ok(BlogPostB.findOne({}, {}) instanceof Query); // query, fields (empty string) assert.ok(BlogPostB.findOne({}, '') instanceof Query); // query, fields, options assert.ok(BlogPostB.findOne({}, {}, {}) instanceof Query); // query, fields (null), options assert.ok(BlogPostB.findOne({}, null, {}) instanceof Query); });
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'); }); });
// 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'); }); });
it('find returns a Query', function() { // query assert.ok(BlogPostB.find({}) instanceof Query); // query, fields assert.ok(BlogPostB.find({}, {}) instanceof Query); // query, fields (empty string) assert.ok(BlogPostB.find({}, '') instanceof Query); // query, fields, options assert.ok(BlogPostB.find({}, {}, {}) instanceof Query); // query, fields (null), options assert.ok(BlogPostB.find({}, null, {}) instanceof Query); });
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 !') })