javascript - How can I test that a callback *doesn't* get run? -
javascript - How can I test that a callback *doesn't* get run? -
i test particular function not run callback during test. eg, in simplified code below, checker.check() checks numbers, , numbers given in particular test should not run callback.
test('do not raise false alerts', function(done){ var checker = setupchecker(function(){ done('bad alert') }) checker.check(60) checker.check(70) checker.check(80) })
essentially test timeout if done()
never called.
i of course of study utilize settimeout()
purpose, thought there might built mocha purpose.
i add together sec callback checker() when alert shouldn't raised, strikes me test-induced design damage , i'd avoid that.
the best place such kind of assertion exit
event of process
, because nil can happen after (well, except other exit
listeners, maintain in mind):
test('do not raise false alerts', function(){ var badalert = false; var checker = setupchecker(function(){ badalert = true }) process.on('exit', function () { assert.ok(!badalert); }); checker.check(60) checker.check(70) checker.check(80) })
unfortunately pattern doesn't work nice mocha. show test passes , stack trace in case of failure.
javascript node.js unit-testing mocha
Comments
Post a Comment