-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async use of verify results in timeout #129
Comments
This is because testdouble.js throws errors on failure as opposed to providing integration with any assertion libraries. You might consider checking out testdouble-chai for assertion integration with Mocha. |
🤔 I think I'm missing something, I don't think I'm using any external assertion library? Instead of throwing a failure telling what the problem is (You called Just to be certain, I tried testdouble-chai. However, I encounter the same problem~~, although even the 'correct' case even blocks execution. (but this is probably a bug from their end)~~ const td = require('testdouble')
const chai = require("chai");
const tdChai = require("testdouble-chai");
chai.use(tdChai(td));
const expect = chai.expect // EDIT: missed expect import here
const { send } = td.replace('./module')
it('should send', done => {
const sender = require('./app').sender
let result = sender().then(() => {
expect(send).to.have.been.calledWith("the message") // => even blocks execution ¯\_(ツ)_/¯
expect(send).to.have.been.calledWith("the message wrong")
done()
})
}) |
tl;dr I don't think this is an issue with testdouble.js, but rather an issue with Mocha and how it works for asynchronous tests. In general, most uses of testdouble.js we want to promote should be accomplished with completely synchronous tests. did read I don't think I know what you mean by "blocks execution". What If you want to use testdouble.js inside a promise let result = sender().then(() => {
throw new Error("hi")
done()
}).catch(done) Otherwise, I suspect Mocha will not know the test is done and will probably time out. I believe if a mocha test More broadly, we don't go out of our way to provide integrations to test frameworks with testdouble.js, but what you're describing might be an opportunity for testdouble-chai to improve. I'm not sure what hooks are available. Finally, it's a shame that Mocha appears to not handle uncaught exceptions gracefully. The same test written with teenytest will detect the uncaught exception and fail immediately and gracefully. |
Great, thank you so much for the detailed answer! Doing awesome work with this library 🙂 |
When a test with a
verify
of a method called in a promise fails, it only blocks further execution instead of throwing an error.eg. running a test with
mocha app.spec.js
app.js
module.js
app.spec.js
The text was updated successfully, but these errors were encountered: