-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
equal and deepEqual use different equality semantics for primitive types #495
Comments
tap and tape aren’t precisely equivalent, so some differences are expected. t.same, in tape, is an alias for deepEqual, not equal. Separately, tape v4 uses deep-equal v1; tape@5 uses deep-equal v2 which more closely matches node’s assert. If you install tape@next, what happens? |
Yes. However, it is expected that const assert = require('assert');
assert.deepEqual([0], [-0]); // passes Upgrading to It looks like the problem stems from using In I think this is a bug — |
deepEqual should match assert; tape should as well. “same” is just an alias, a convenience; it has no direct expectations. I very recently updated deep-equal and tape, and that involved changes to -0 handling, so I’m quite convinced there’s not a bug here, but if you’d like to submit a PR with failing test cases, I’d be happy to look into it. |
@ljharb I think there's a misunderstanding there — I know
That's exactly what I'm saying — it should, but currently An additional argument (beyond incompatibility with Node's t.equal(0, -0); // ok
t.deepEqual(0, -0); // fail |
They often have different results; try 3 and '3', for example. There’s a bug if assert.equal doesn’t match t.equal, and assert.deepEqual doesn’t match t.deepEqual. The strict option should match assert.deepStrictEqual. |
Ah, yeah, you're right, although the fact
Edit: updated the issue title/description to describe the issue more precisely. |
So, if tape and deep-equal are both consistent with node's |
@ljharb sorry if I'm not expressing myself clearly enough — see my comment above, which shows how |
Here's what I see on latest master (tape@next)
Which shows that there is indeed a mismatch between |
@ljharb exactly! Thank you very much! |
@ljharb thanks a lot for addressing this! Thinking about this further, if
As a part of semver-major change which you're doing anyway, would it makes sense to do:
|
I think that it's generally an improvement for tape to default to strictDeepEqual, and make "loose" opt-in. If anything, it'd be reasonable to swap |
- `is`/`isNot`/`not`/`notStrictEqual`/`notStrictEquals`: use `Object.is` instead of `===` - `notEqual`/`notEquals`/`isNotEqual`/`doesNotEqual`/`isInequal`: use `==` instead of `===` See #495
Added 24240e2 as well, to ensure all the inverse functions were consistent. |
@ljharb it still seems weird to me that |
I don't know the history; I think this is just the way it's been for awhile - but basically this is a question of tradeoffs: is the consistency worth the breakage and churn? I'm not convinced it is. |
@ljharb if we're worried about breakage and churn, why should we introduce the big change of On the other hand, if we want to keep things mostly as they were before but improve consistency, why not revert the |
That won't break anything - currently passing tests will continue to pass. That's also a reasonable alternative, true - making |
The more I think about that suggestion, the more I like it:
|
@ljharb 🎉 excellent! I like this way much more too. Thanks a lot for your patience bearing through all my comments, and generally really great work maintaining this awesome project. |
Tape 5.0.0 introduces specific strict/loose comparisons for `deepEqual` and similar methods: https://github.com/substack/tape#tdeeplooseequalactual-expected-msg See tape-testing/tape#495 for the original discussion
Tape 5.0.0 introduces specific strict/loose comparisons for `deepEqual` and similar methods: https://github.com/substack/tape#tdeeplooseequalactual-expected-msg See tape-testing/tape#495 for the original discussion
Tape 5.0.0 introduces specific strict/loose comparisons for `deepEqual` and similar methods: https://github.com/substack/tape#tdeeplooseequalactual-expected-msg See tape-testing/tape#495 for the original discussion
Consider the following assertion:
It passes because JavaScript defines strict equality between signed zeroes (
0 === -0
). However, the following scenario unexpectedly fails:Discovered this while switching from
tap
totape
— the latter had a failing case where tap passed because of this inconsistency. cc @ljharbThe text was updated successfully, but these errors were encountered: