From db99cbccdb4f5357db1175f798a7c0a07d65a963 Mon Sep 17 00:00:00 2001 From: Muthu Kumar Date: Tue, 4 Sep 2018 12:51:27 +0530 Subject: [PATCH] [tests] Update tests --- sample/sample.test.js | 33 +++++++++++++++++++++------------ sample/sample2.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 sample/sample2.test.js diff --git a/sample/sample.test.js b/sample/sample.test.js index cace0b0..b7efe11 100644 --- a/sample/sample.test.js +++ b/sample/sample.test.js @@ -7,10 +7,10 @@ const Gunner = require('../index.js'); const gunner = new Gunner({ name: 'sample tests' }); const a = 1; -gunner.before(Gunner.Start, () => console.log('Started tests!')); -gunner.before(Gunner.End, () => console.log('Ended tests!')); -let runCount = 1; -gunner.before('*', () => console.log(`Running test ${runCount++}`)); +// gunner.before(Gunner.Start, () => console.log('Started tests!')); +// gunner.before(Gunner.End, () => console.log('Ended tests!')); +// let runCount = 1; +// gunner.before('*', () => console.log(`Running test ${runCount++}`)); gunner.test('should automatically pass', expect => expect().done()); gunner.test(`should be equal`, expect => expect(1).equal(1)); @@ -23,18 +23,27 @@ gunner.test('should be a Promise (resolved)', expect => gunner.test('should be a Promise (rejected)', expect => expect(Promise.reject()).isPromise()); +gunner.test('wait and resolve', () => { + return new Promise(r => { + setTimeout( + () => r('ok'), + 500 + ); + }); +}); + gunner.test('should resolve to 5', expect => expect(Promise.resolve(5)).resolvesTo(5)); -gunner.before( - 'file must have hello as content', - () => console.log('>> starting test! file must have hello as content'), -); +// gunner.before( +// 'file must have hello as content', +// () => console.log('>> starting test! file must have hello as content'), +// ); -gunner.after( - 'file must have hello as content', - () => console.log('>> finished test! file must have hello as content'), -); +// gunner.after( +// 'file must have hello as content', +// () => console.log('>> finished test! file must have hello as content'), +// ); gunner.test('file must have hello as content', async expect => { const { readFile } = require('fs').promises; diff --git a/sample/sample2.test.js b/sample/sample2.test.js new file mode 100644 index 0000000..8ffb9c2 --- /dev/null +++ b/sample/sample2.test.js @@ -0,0 +1,25 @@ +/** + * This file contains random tests + * used during development + */ + +const Gunner = require('../index.js'); +const gunner = new Gunner({ name: 'state tests' }); + +gunner.before(Gunner.Start, () => 'hello'); +gunner.before(Gunner.Start, () => 'below'); +gunner.before(Gunner.Start, () => 'shallow'); +gunner.before('*', () => 'stars'); +gunner.before('Test 1', () => 'nope'); + +gunner.test('Test 1', (expect, state) => + [ + expect(state['@start']).deepEquals([ 'hello', 'below', 'shallow' ]), + expect(state['@every']).deepEquals([ 'stars' ]), + expect(state['@this']).deepEquals([ 'nope' ]), + ]); + +gunner.test('(should fail) Test 2', (expect, state) => + expect(state['@start']).deepEquals([ 'hellno' ])); + +gunner.run({ log: true }); \ No newline at end of file