Open crimx opened 6 years ago
Is this problem related to https://github.com/acvetkov/sinon-chrome/issues/66 ?
No I think it was related to Sinon. I was using vue-cli which generates Sinon v4.x dependency. I think it might not be compatible with Sinon Chrome.
Anyway I ended up using jest with sinon-chrome and let jest handle the matching,
I've encountered the same issue, it seems that it's not possible to use sinon.match
if sinon
isn't the very instance sinon-chrome
is using internally.
Here's how one can reproduce:
test
1
and folder 2
inside test
test/1
: npm install sinon
test/2
: npm install sinon-chrome
test/2
create test.js
with the following content and execute with node test.js
const sinon = require('sinon');
const browser = require('sinon-chrome/webextensions');
browser.tabs.create({foo: 'bar'});
console.log(browser.tabs.create.calledWith({
foo: sinon.match.string
}));
const otherSinon = require('../1/node_modules/sinon');
console.log(browser.tabs.create.calledWith({
foo: otherSinon.match.string
}));
true
false
true
true
This is a rather fabricated example, but I've seen it happen inside just one module since I believe it's still possible that different version reside in the same node_modules folder
A workaround is to pass in your own sinon or use the exposed sinon from sinon-chrome
, I'll provide a Pull request for that.
My guess is that sinon does some sort of instanceOf
test or something, not sure if this can be solved in a generic way.
I think peer dependency is for this kind of issue. How about making sinon a peerDependency <5.0.0
.
I'd agree that's a good idea. This can be a really time-consuming edge-case, compared to an initial "you have to install sinon yourself"-hint to get it working (in a reliable way).
I'm having trouble making sinon-chrome stubs work with
sinon.match
.I use webpack, karma, mocha and sinon-chai. The spec below may reproduce the error.
It looks like sinon-chrome's stub doesn't recognize
sinon.match
and treats it like a normal object. The error is "AssertionError: expected stub to have been called with arguments hasOwn("key")%D", while it should be "arguments matching hasOwn("key")%D".Any idea what went wrong?
Results: