-
Notifications
You must be signed in to change notification settings - Fork 16
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
assert.equal doesn't give nice output if truncate threshold is reached #7
Comments
Hm, I looked into a fix along these lines:
and then passing This failed and debugging it I found out that |
Note that:
is a workaround. It still tries to show me useless diffs on how the underlying objects differ, though. |
But I suspect due to the Collection instance not being reliable I get an assertion failure where two immutable objects that should be the same are considered not to be... |
In the end I decided to forgo chai entirely for this kind of testing and replace it with a simple extension to node's assert:
so far it's much more reliable. You could consider something similar: add an 'is' which assumes immutable objects, instead of trying to override equal to mean something in addition to its original meaning. |
Waouh @faassen, that's a detailed bug report! :-) |
Yes this is the same issue I reported on 24. Not sure how I missed this issue. Here's what I've observed: it('does not give helpful test output?', () => {
const expected = Map({
entries: List.of('Trainspotting')
});
const actual = Map({
entries: List.of('28 Days Later')
});
expect(expected).to.eql(actual);
}); Yields the following output: AssertionError: expected { Object (size, _root, ...) } to equal { Object (size, _root, ...) } If I convert my immutables to regular JS objects, like below, I get output like what I was expecting: it('has helpful output with JS objects', () => {
const expected = Map({
entries: List.of('Trainspotting')
});
const actual = Map({
entries: List.of('28 Days Later')
});
expect(expected.toJS()).to.eql(actual.toJS());
}); Output: AssertionError: expected { entries: [ 'Trainspotting' ] } to deeply equal { entries: [ '28 Days Later' ] }
+ expected - actual
{
"entries": [
- "Trainspotting"
+ "28 Days Later"
]
} |
@kmckee I'm working on a fix and it should land soon. Stay tuned. |
Awesome! In the mean time, if anyone else is having the same problem, I've started to just call toJS() on my immutables when asserting with them, and then using POJOs for the expected values. I get nice output and I can easily remove them later with something like: grep -r expect.*toJS ./test |
@kmckee, 08edf4a should fix this issue. Can you confirm that this commit and subsequent commits after that do work in your case? I know it's been a while, but that would be awesome to also have @faassen give his feedback on this. Let me know if you have anything to add, and thanks again fore reporting this in the first place :-) |
Confirmed. Thanks a ton!! Error message displayed is: |
Great to see this fixed! 👍 When will this fix be published to npm? |
Oops, sorry @rogeriopvl, I was so busy I guess I dropped the ball after @kmckee replied... Anyway, done: [email protected] is now published! Thanks all for your patience, your helpful reports and encouragement, especially @faassen whom I ended up ignoring for 8+ months! |
Consider this assertion:
This fails with this ugly error:
I debugged why I sometimes got this kind of error. It's because the length of the string representation of the actual value exceeds Chai's truncate threshold. Chai then proceeds to fall back to another method and displays the object in a truncated fashion.
I don't think it looks like Chai's objDisplay function can be easily taught about truncating Immutable.js's values. So I think it would be best to detect whether what we pass into actual (or expected) is an Immutable object, and if so, pass in the string instead of the object itself. It should then pass through without harm.
The text was updated successfully, but these errors were encountered: