UNPKG

siesta-lite

Version:

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

124 lines (104 loc) 3.75 kB
StartTest(function(topTest) { //================================================================================================================================================================================== topTest.diag("Siesta.Test creation") topTest.expectPass(function (t) { var async = t.beginAsync(1000) setTimeout(function () { t.endAsync(async) }, 500) }) topTest.expectFail(function (t) { t.beginAsync(1000) }) topTest.testExtJS( { doNotTranslate : true }, function (t) { t.beginAsync(1000, function (t) { t.fail('baz') return true }) }, function (test) { topTest.is(test.getAssertionCount(), 1, "One assertion in test") topTest.notOk(test.results.itemAt(0).passed, "And its failing") topTest.is(test.results.itemAt(0).description, "baz", "And it was generated by errback") } ) topTest.testExtJS( { doNotTranslate : true, defaultTimeout : 1000 }, function (t) { t.chain( // this step will never complete - and it should be reported function (next) { // to trick the step content analyzer return "next()" }, function () { } ) }, function (test) { topTest.is(test.getAssertionCount(), 1, "One assertion in test") topTest.notOk(test.results.itemAt(0).passed, "And its failing") topTest.like(test.results.itemAt(0).description, "within required timeframe", "And it was generated by step timeout") } ) topTest.testExtJS( { doNotTranslate : true, waitForTimeout : 100 }, function (t) { t.chain( { // this step will never complete - and it should be reported with single(!) failed assertion, not 2 assertions waitFor : function () {} }, function () { } ) }, function (test) { topTest.is(test.getAssertionCount(), 1, "One assertion in test") topTest.notOk(test.results.itemAt(0).passed, "And its failing") topTest.like(test.results.itemAt(0).description, "Waited too long for", "And it was generated by the `waitFor` action") } ) topTest.testExtJS( { doNotTranslate : true, defaultTimeout : 1500 }, function (t) { t.chain( { action : 'done' } ) }, function (test) { topTest.is(test.getAssertionCount(), 0, "No failing assertions in test") } ) topTest.testExtJS( { doNotTranslate : true }, function (t) { t.chain( // somehow "wait" action could prematurely finalize the test { action : 'wait', delay : 500 }, function () { t.pass('checkpoint') } ) }, function (test) { topTest.is(test.getAssertionCount(), 2, "2 assertions in test - 1st is `waitFor` and 2nd - checkpoint") topTest.is(test.results.itemAt(1).description, 'checkpoint', "2n assertion was generated by the checkpoint step") } ) })