Created
September 30, 2016 02:23
-
-
Save anonymous/cc71303a6a3362873eed1baf251c96e6 to your computer and use it in GitHub Desktop.
test mocha behavior on errors after timeout
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
describe("with done:", function() { | |
it("done(error) after timeout", function(done) { | |
this.timeout(10) | |
setTimeout(function() { done(new Error("GOTCHA!")) }, 100) | |
}) | |
it("this one is safe because error is reported through done", function(done) { | |
this.timeout(5000) | |
setTimeout(done, 1000) | |
}) | |
}) |
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
*.js --slow 10000 |
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
{ | |
"scripts": { | |
"pretest:old": "npm i mocha@2.x", | |
"test:old": "npm run test:run", | |
"pretest:new": "npm i mocha@3.x", | |
"test:new": "npm run test:run", | |
"test:run": "mocha --version && mocha --opts mocha.opts", | |
"test": "npm run test:old || npm run test:new" | |
} | |
} |
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
describe("with promise:", function() { | |
it("reject after timeout", function(done) { | |
this.timeout(10) | |
return new Promise(function(resolve, reject) { | |
setTimeout(resolve, 100) | |
}).then(function() { throw new Error("GOTCHA!") }) | |
}) | |
it("this one is safe because error is reported through promise", function(done) { | |
this.timeout(5000) | |
setTimeout(done, 1000) | |
}) | |
}) |
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
describe("with throw:", function() { | |
it("throw after timeout", function(done) { | |
this.timeout(10) | |
setTimeout(function() { throw new Error("GOTCHA!") }, 100) | |
}) | |
it("if the other test was not timing out, it would not interfere with this one", function(done) { | |
this.timeout(5000) | |
setTimeout(done, 1000) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment