Comments (12)
Note that:
chai.config.truncateThreshold = 0;
is a workaround. It still tries to show me useless diffs on how the underlying objects differ, though.
from chai-immutable.
Hm, I looked into a fix along these lines:
var collectionRepr = (collection instanceof Collection ?
collection.toString() :
collection);
and then passing CollectionRepr, obj.toString()
as the last two arguments into this.assert
.
This failed and debugging it I found out that obj instanceOf Collection
does not always hold true; there are Immutable objects where this is false
. How to replicate it yet I don't know, but I have a set here that gives true
to Immutable.isSet()
but false to
obj instanceof Collection`...
from chai-immutable.
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...
from chai-immutable.
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:
assert.is = function(actual, expected, message) {
if (!Immutable.is(actual, expected)) {
assert.fail(actual, expected, message, "is", assert.is);
}
};
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.
from chai-immutable.
Waouh @faassen, that's a detailed bug report! :-)
Thanks for sharing, give me a few days to finish what's on my priority queue and I'll get back to this to come up with a solution!
from chai-immutable.
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"
]
}
from chai-immutable.
@kmckee I'm working on a fix and it should land soon. Stay tuned.
from chai-immutable.
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
from chai-immutable.
@kmckee, 08edf4a should fix this issue. Can you confirm that this commit and subsequent commits after that do work in your case?
I'll release a patch version when you can confirm.
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 :-)
Sorry I dropped the ball on you for months!
from chai-immutable.
Confirmed. Thanks a ton!!
Error message displayed is:
AssertionError: expected 'Map { "entries": List [ "Trainspotting", "28 Days Later" ] }' to equal 'Map { "entries": List [ "Traiinspotting", "28 Days Later" ] }'
from chai-immutable.
Great to see this fixed! 👍
When will this fix be published to npm?
from chai-immutable.
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!
from chai-immutable.
Related Issues (20)
- Add support for custom messages HOT 1
- Support reference comparison HOT 8
- [email protected]" has incorrect peer dependency "immutable@^3.0.0". HOT 4
- latest immutablejs support(Is this library even alive?) HOT 5
- Dependency Dashboard
- Publish new version! HOT 3
- Replace JSCS with ESLint
- Use ES6 in the documentation HOT 1
- `not` in assertions is ignored HOT 4
- Publish version HOT 3
- App crash if receive an REMOTE_WIDGET_DRAGGING or UPDATE_WIDGET before mural is fully loaded HOT 2
- Add `.deep.include` for deep equality comparisons
- Add support for deep flag for the keys assertion
- Drop support of Node v0.10 and v0.12
- Support Chai v4's `.deep.property`
- Write comprehensive tests for `.not.property` HOT 2
- Feature request: comparison of Maps via include HOT 3
- npm WARN [email protected] requires a peer of chai@>= 2.0.0 < 4 but none was installed. HOT 9
- Investigate potential remaining items for Chai v4 support HOT 8
- Cannot find module 'immutable' HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chai-immutable.