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

assertStrictEquals(-0, +0) should not throw #4714

Closed
rherrmann opened this issue May 11, 2024 · 5 comments · Fixed by #4715 or #4724
Closed

assertStrictEquals(-0, +0) should not throw #4714

rherrmann opened this issue May 11, 2024 · 5 comments · Fixed by #4715 or #4724
Labels
bug Something isn't working good first issue Good for newcomers needs triage

Comments

@rherrmann
Copy link
Contributor

Describe the Bug
According to the Strict Equality Comparison Algorithm of the Javascript standard, -0 and +0 are considered equal.

Assuming that assertStrictEquals is meant to assert equality in the sense of actual === expected, it should not throw when passing -0 and +0 for actual and expected.

Steps to Reproduce

import { assert, assertStrictEquals } from "https://deno.land/[email protected]/assert/mod.ts";

assert(-0 === +0); // passes
assertStrictEquals(-0, +0); // fails

Expected Behavior
assertStrictEquals(-0, +0) should not throw.

Environment

  • OS: macOS
  • deno version: 1.43.2
  • std version: 0.224
@rherrmann rherrmann added bug Something isn't working needs triage labels May 11, 2024
@ry ry added the good first issue Good for newcomers label May 11, 2024
rherrmann added a commit to rherrmann/deno_std that referenced this issue May 11, 2024
rherrmann added a commit to rherrmann/deno_std that referenced this issue May 11, 2024
rherrmann added a commit to rherrmann/deno_std that referenced this issue May 11, 2024
Fix `assertStrictEquals` to consider -0 and +0 to be equal. Follow the
[MDN recommendation] by replacing `Object.is` with `===` and handling
NaNs specifically.

[MDN recommendation]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#when_to_use_object.is_versus_triple_equals
iuioiua pushed a commit that referenced this issue May 12, 2024
fix(assert): let assertStrictEquals(-0, +0) pass (#4714)

Fix `assertStrictEquals` to consider -0 and +0 to be equal. Follow the
[MDN recommendation] by replacing `Object.is` with `===` and handling
NaNs specifically.

[MDN recommendation]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#when_to_use_object.is_versus_triple_equals
@kt3k
Copy link
Member

kt3k commented May 13, 2024

Note: In Node.js, +0 and -0 are not equal with assert.strictEqual assertion. I'm not sure the suggested behavior is expected

@iuioiua iuioiua reopened this May 13, 2024
@iuioiua
Copy link
Contributor

iuioiua commented May 13, 2024

That's a fair point. Should we adhere to ECMA's definition of strict equality (===) or mimic Node's implementation, which uses Object.is()?

@kt3k
Copy link
Member

kt3k commented May 13, 2024

Jest and Vitest also follow what Node.js does. The below examples throw in jest and vitest:

Jest

expect(+0).toStrictEqual(-0);

Vitest

import { expect, test } from 'vitest'
expect(+0).toStrictEqual(-0);

@iuioiua
Copy link
Contributor

iuioiua commented May 13, 2024

Ok. I'll revert and instead add a note explaining the behavior.

@iuioiua
Copy link
Contributor

iuioiua commented May 13, 2024

fix(assert): handle assertStrictEquals(-0, +0) correctly #4715

See #4718

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers needs triage
Projects
None yet
4 participants