UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

103 lines (83 loc) 2.98 kB
StartTest(t => { t.it('Analyzing chain step should work', t => { t.testBrowser(t => { var document = t.global.document t.ok( t.analyzeChainStep(next => next++), 'Correctly found usage of 1st argument in step function' ) t.ok( t.analyzeChainStep(( next ) => { next++; }), 'Correctly found usage of 1st argument in step function' ) t.ok( t.analyzeChainStep((abc123_11, zxc, zz) => { abc123_11++; }), 'Correctly found usage of 1st argument in step function' ) t.notOk( t.analyzeChainStep(() => { next() }), 'Correctly found the absence of 1st argument in step function' ) t.notOk( t.analyzeChainStep((next) => { var a = 1 }), 'Correctly found the absence of usage of 1st argument in step function' ) }) }) t.it('Returning promise from chain step should work', t => { t.testBrowser(t => { let someAsyncOperation = t => new Promise((resolve, reject) => { t.pass("Starting async stuff") setTimeout(() => { resolve("someValue") }, 300) }) t.chain( function (next) { return new Promise((resolve, reject) => { setTimeout(() => resolve('fooji'), 300) }) }, function (next, res) { t.is(res, 'fooji', 'Correct result in the next step') next() }, async () => { return await someAsyncOperation(t) }, function (next, res) { t.is(res, 'someValue', 'Correct result in the next step') } ) }) }) t.it('Returning promise from chain step should timeout correctly', t => { t.testBrowser( { doNotTranslate : true, defaultTimeout : 300 }, t => { t.chain( function (next) { return new Promise((resolve, reject) => { }) }, function (next, res) { } ) }, test => { t.notOk(test.isPassed(), "Test is failed") } ) }) t.it('Returning promise from chain step and calling a callback of `waitFor` should work', t => { t.chain( next => t.waitForFn(() => true, next), // give some time for promise from the previous step to resolve next => t.waitFor(10) ) }) })