Description
Version
2.5.8
Reproduction link
https://jsbin.com/lujehap/edit?html,js,output
Steps to reproduce
Run tests in repro link :)
What is expected?
Both tests should fail with similar error messages
What is actually happening?
The first test, using setTimeout, fails as expected, but with the second test, using Vue.nextTick(), just times out, with the error disappearing.
This is happening because Vue.nextTick()
apparently uses a promise internally and mocha doesn't support catching unhandled promise errors.
There is a workaround, but it isn't great:
window.addEventListener('unhandledrejection', (e) => {
throw e;
});
That at least lets you know that there was an error, but doesn't log the correct error.
You can also wrap the contents of the test in setTimeout
:
it('should catch errors from Vue.nextTick()', (done) => {
Vue.nextTick(() => {
setTimeout(() => {
throw new Error('test');
done();
});
});
});
That will ensure that mocha knows about them.
While this is mostly a problem with mocha, I think it is unexpected that you have to handle errors inside Vue.nextTick()
as if in a promise - it doesn't look like a promise from the function!
I'm not really sure what I would suggest doing about this.