-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Jasmine 3.2.0 breaks spyOn().and.returnValue(Promise.reject()) #1590
Comments
Hmmm, it seems like this might be some kind of side effect from trying to capture unhandled rejections to report them with the spec, but I can get a reproduction case where the spy isn't actually installed. The extra stripped down example that I think should be equivalent to what you've got is (this should just strip out your const foo = { bar: function() {} };
async function main(callback) {
try{
await foo.bar();
return callback();
} catch(e) {
console.error(e);
}
}
describe("Apple", function() {
it("mercury", function(done) {
const thingSpy = spyOn(foo, 'bar').and.returnValue(Promise.reject({ message: 'failure' }));
main(() => {
expect(thingSpy).toHaveBeenCalled();
done();
});
});
}); When I run this the Let me know if there is something crucial I stripped out in my sample spec or something else I've missed that might be contributing to the error. |
A change in Jasmine 3.2 seems to be responsible for the recent CI failures. Pinning it to 3.1 for now. See apache/cordova-ios#393, See jasmine/jasmine#1590 See #636
Any update here? |
As I mentioned above, I haven't been able to reproduce this error, which makes it difficult to find a solution. If you can provide a simplified suite with all of the code that reproduces the issue, I'll be happy to take another look. |
I think I have a repro, but using file is saved as 'use strict';
const bar = {
test() {
return Promise.resolve('Hello World');
},
};
describe('bar', () => {
fit('jasmine suite error', async () => {
// multiple return values to test calls that may fail
// a few times but succeed after a few retries
spyOn(bar, 'test').and.returnValues(
Promise.reject(new Error('bad')),
Promise.reject(new Error('worse')),
Promise.resolve('things are ok'),
);
try {
await bar.test();
fail();
} catch (err) {
expect(err.message).toBe('bad');
}
expect(bar.test).toHaveBeenCalled();
});
}); running it, I get the following output:
It seems like if you have Based on the output though, the test succeeded, but the error was still thrown. I have a few tests where I have retry logic around code that makes network calls, and I use I updated another project to Jasmine 3.3.0 and had to fix this in a few tests of mine just last week. For whatever reason I can't create a simple repro using just if I use
|
My best guess here is that Node.js itself is detecting that the rejected promise exists and no code setup an error handler before it went out of scope and that is where the error is coming from. The fact that you're seeing different behavior when you use Bluebird seems to confirm some of this. I'm not sure what Jasmine can do to help with this. A workaround you might try is to use Hope this helps. Thanks for using Jasmine! |
^ Agree on the workaround. Personally, I don't feel this is is a jasmine issue at all, it's a Bluebird issue. The fix in general is to just never create rejected promises until you need them (from a jasmine perspective, that means always |
…son/jasmine into elliot-nelson-enelson/spystrategies - Merges #1688 from @enelson - See #1590
Agreed. I don't think Jasmine can allow |
Expected Behavior
When trying to create a spy using spyOn(things, 'function).and.returnValue(Promise.reject()), I expect the function to have a spy.
Current Behavior
When trying to create a spy using spyOn(things, 'function).and.returnValue(Promise.reject()), the function does not change to a spy. It is the original function still. Doing so with a Promise.resolve() correctly makes a spy.
Logging out fetch.fetch within main shows the actual fetch function instead of the spy.
This behavior worked as intended until jasmine updated to 3.2.0;
Context
Jasmine updating to 3.2.0 (via Package.json of ^3.0.0) broke our build machine of previously passing tests.
Your Environment
The text was updated successfully, but these errors were encountered: