-
-
Notifications
You must be signed in to change notification settings - Fork 277
-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Sinon Chai calledWithMatch causes structuredClone to error in the test runner #2772
Comments
This is blocking our (@novnc) migration to web test runner, as we make heavy use of sinon. :/ Have you found any way to work around the issue? |
@CendioOssman A quick work around would be to delete the it('stops working when errors', () => {
const sinonSpy = spy();
sinonSpy();
try {
expect(sinonSpy).to.be.calledWithMatch({ foo: 'bar' });
} catch (e) {
delete e.actual;
throw e;
}
}); |
Thanks. That doesn't scale terribly well. And we have 765 such assertions. Any workaround would need to be somewhere more central. :/ |
For a central work around I would implement the work around in a Chai plugin: import { use, Assertion } from 'chai';
import sinonChai from 'sinon-chai';
function overrideCallWithMatch() {
Assertion.overwriteMethod('calledWithMatch', _super => {
return function() {
try {
_super.apply(this, arguments)
} catch (error) {
delete error.actual;
throw error;
}
}
});
}
use(sinonChai);
use(overrideCallWithMatch); Depending on for which Sinon Chai methods you want to implement the work around you can extend the plugin. Would this help you @CendioOssman ? |
I have the same issue. This is an issue with any value that My current workaround is to lock |
I was running into this with Both workarounds (wrapper and pinning to |
Possibly. It is a bit annoying that you have to do it for a bunch of methods, though. But I supposed that can be optimized a bit.
This workaround does not work for me. Is there a regression in 0.7.2 that causes this problem? |
I think it is this change that causes the problem: 4a4b699. To be more precise, the usage of |
Hmm.. Very odd that it didn't resolve the issue here for me in that case. @lucaelin, is this issue something you are aware of and working on? |
Hey, thanks for bringing this second issue to my attention, I will see what I can do this weekend, |
See this repo for a reproduction https://github.com/Sanderovich/web-test-runner-called-with-match-error-reproduction.
When an
expect(spy).to.be.calledWithMatch()
is unsuccesful the expect throws anAssertionError
that web test runner can not handle which causes the following exception.The crash seems to happen because of the
actual
property inside theAssertionError
. Theactual
property is set to a function called proxy andstructuredClone
cannot handle functions (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).A possible solution could be to
JSON.stringify()
andJSON.parse()
theAssertionError
before thestructuredClone
.The text was updated successfully, but these errors were encountered: