-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
redux-saga select with selection creators #746
Comments
Hey @JuHwon thanks for the issue. It is indeed because you have two functions - which although they have the same behaviour, are different references. There are a few "workarounds" I suppose:
I don't think we want to change the behaviour to make two functions return true for deep equality, so this (calling .deep.equal) will likely never work. |
Thanks for your answer. I've written a custom helper method for my use case. |
@JuHwon I'm running through the same issue. What did you finally chose to do, to be able to compare the two objects ? |
@Neophy7e I implemented something like this: /**
* Chai Plugin for testing redux saga combined with selector creator functions
* This expectEqual is implemented like the implementation of expect (https://github.com/mjackson/expect)
*/
import { Assertion, util } from 'chai';
import whyNotStrictlyEqual from 'is-equal/why';
const whyNotEqual = (a, b) =>
(a == b ? '' : whyNotStrictlyEqual(a, b));
const isEqual = (a, b) => whyNotEqual(a, b) === '';
Assertion.addMethod('expectEqual', function(expected, msg) {
if (msg) {
util.flag(this, 'message', msg);
}
util.expectTypes(this, ['object']);
const actual = util.flag(this, 'object');
this.assert(
isEqual(actual, expected)
, 'expected #{this} to expectEqual #{exp}\n' + whyNotStrictlyEqual(actual, expected)
, 'expected #{this} to not expectEqual #{exp}'
, expected
, this._obj
, util.flag(this, 'negate') ? true : false
);
}); this is not 100% fully tested so its kinda a draft. though it worked for my use cases. |
Thank you @JuHwon :) I'll let you know if I perform changes on it to improve it |
Hi i am using chai to assert my unit tests in my redux application.
I got an issue where chai tells me that the objects are not the same, though if i use expect it works fine. I think this is because one property is a returned function of a function.
I made a fiddle to make things clear.
Is there a way to test such a thing with chai too? I would like to stay with chai, though this is a must have for me.
The text was updated successfully, but these errors were encountered: