Skip to content
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

Closed
JuHwon opened this issue Jul 4, 2016 · 5 comments
Closed

redux-saga select with selection creators #746

JuHwon opened this issue Jul 4, 2016 · 5 comments

Comments

@JuHwon
Copy link

JuHwon commented Jul 4, 2016

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.

@keithamus
Copy link
Member

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.

@JuHwon
Copy link
Author

JuHwon commented Jul 5, 2016

Thanks for your answer. I've written a custom helper method for my use case.

@JuHwon JuHwon closed this as completed Jul 5, 2016
@BentoumiTech
Copy link

@JuHwon I'm running through the same issue. What did you finally chose to do, to be able to compare the two objects ?

@JuHwon
Copy link
Author

JuHwon commented Aug 2, 2016

@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.

@BentoumiTech
Copy link

Thank you @JuHwon :) I'll let you know if I perform changes on it to improve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants