Last active
September 26, 2016 13:29
-
-
Save mrkvon/6caadea482f4e624f96a3b824d97ac69 to your computer and use it in GitHub Desktop.
example of asynchronous tests with should
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// assertion passes - test passes | |
it('[first reply] should give tag with key `position` and value `first_reply`', function (done) { | |
messageToInfluxService.process(message2to1, function (err, fields, tags) { | |
if (err) return done(err); | |
try { | |
tags.should.have.property('position', 'first_reply'); | |
return done(); | |
} catch (e) { | |
return done(e); | |
} | |
}); | |
}); | |
// assertion passes - test passes (without try catch) | |
it('[first reply] should give tag with key `position` and value `first_reply`', function (done) { | |
messageToInfluxService.process(message2to1, function (err, fields, tags) { | |
if (err) return done(err); | |
tags.should.have.property('position', 'first_reply'); | |
return done(); | |
}); | |
}); | |
// assertion fails - test fails with a proper error | |
it('[first reply] should give tag with key `position` and value `first_reply`', function (done) { | |
messageToInfluxService.process(message2to1, function (err, fields, tags) { | |
if (err) return done(err); | |
try { | |
tags.should.have.property('position', 'first_replay'); // note the different assertion | |
return done(); | |
} catch (e) { | |
return done(e); | |
} | |
}); | |
}); | |
// missing try - catch | |
// (!) assertion fails - test fails with UnhandledPromiseRejectionWarning printed in console and with timeout | |
it('[first reply] should give tag with key `position` and value `first_reply`', function (done) { | |
messageToInfluxService.process(message2to1, function (err, fields, tags) { | |
if (err) return done(err); | |
tags.should.have.property('position', 'first_replay'); | |
return done(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment