debitoor / chai-subset

"containSubset" object properties matcher for Chai
http://chaijs.com/plugins/chai-subset/
MIT License
82 stars 20 forks source link

Chai subset executes redux-saga call? #68

Open clementhannicq opened 6 years ago

clementhannicq commented 6 years ago

Hello, I was using chai-subset to test a generator function(using redux-saga)

Running the following snippet does not execute fn

const {value} = mySaga.next();
const object = call(fn, param);

console.log(object);

Running this one runs the function fn

const {value} = mySaga.next();
const object = call(fn, param);

expect(value).to.containSubset(object);

To be noted, using deep.equal does not execute it

const {value} = mySaga.next();
const object = call(fn, param);

expect(value).to.deep.equal(object);

If you are unfamiliar with redux-saga, call returns an object containing the function and its parameters

EDIT: After reading the README, I figure it happens because chai-subset allows functions to compare values, renhancement proposal: add a setting to disable function execution

elmigranto commented 5 years ago

Yeah, when it sees a function, it calls it, which in addition to not making it possible to compare functions, throws a TypeError on constructors.

You can transform your object so when it sees a function in value, it replaces it with a check that comparing against that value, or, alternatively, 1.5.0 should work which is version before #66 was merged. @clementhannicq

@eagleeye that's a great module, thanks for making it public, but not being able to compare values without boilerplate is somewhat a big bug for this kind of lib. I feel that current behaviour is very niche and should be either reverted or made opt-in (also, breaking change between 1.5.0 and 1.6.0).