-
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
thenThrow does not work if stub passed down #319
Comments
Can you please provide a reproducible example? This doesn't seem right and the example isn't enough to debug with |
running on mac node 8-lts const td = require('testdouble');
describe.only('', () => {
function funcCaller(func) {func()}
const obj = td.object({throw: () => {}});
it('Shold throw error', () => {
td.when(obj.throw()).thenThrow(new Error('HAAAAA'));
try {
obj.throw();
}
catch(e) {
console.log('YAY'); // works as expected
}
});
it('Shold throw error2', () => {
td.when(obj.throw()).thenThrow(new Error('HAAAAA'));
try {
funcCaller(obj.throw);
}
catch(e) {
console.log('YAY'); // never gets here
}
});
}); |
In test runners like mocha & jasmine, it's unsafe to execute any per-test code inside of a As a result, you should definitely have the Changed example: describe.only('', () => {
function funcCaller(func) {func()}
it('Shold throw error', () => {
const obj = td.object({throw: () => {}});
td.when(obj.throw()).thenThrow(new Error('HAAAAA'));
try {
obj.throw();
}
catch(e) {
console.log('YAY'); // works as expected
}
});
it('Shold throw error2', () => {
const obj = td.object({throw: () => {}});
td.when(obj.throw()).thenThrow(new Error('HAAAAA'));
try {
funcCaller(obj.throw);
}
catch(e) {
console.log('YAY'); // never gets here
}
});
}); |
Hi, for some reason (context?) when using thenThrow, the method wont throw if it is being passed to another method
Example:
The text was updated successfully, but these errors were encountered: