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

assertEquals doesn't correctly compare Blobs #6202

Closed
EvanHahn opened this issue Nov 22, 2024 · 2 comments · Fixed by #6210
Closed

assertEquals doesn't correctly compare Blobs #6202

EvanHahn opened this issue Nov 22, 2024 · 2 comments · Fixed by #6210
Labels
docs wontfix This will not be worked on

Comments

@EvanHahn
Copy link
Contributor

Describe the bug

assertEquals doesn't consider value-equal Blobs to be equal.

Steps to Reproduce

Run the following code:

import { assertEquals } from "jsr:@std/assert";
assertEquals(new Blob(["foo"]), new Blob(["foo"]));

Expected behavior

This should not throw an error. Instead, it throws AssertionError: Values are not equal.

Environment

  • OS: macOS 15
  • deno version: 2.1.0
  • std version: 1.0.8
@EvanHahn EvanHahn added bug Something isn't working needs triage labels Nov 22, 2024
@kt3k kt3k removed the needs triage label Nov 22, 2024
@IgorM867
Copy link
Contributor

To compare Blob objects, assertEquals needs to handle asynchronous operations. One approach could be transforming Blob objects into Uint8Array:

import { assertEquals } from "@std/assert";

const bytes1 = await new Blob(["foo"]).bytes();
const bytes2 = await new Blob(["foo"]).bytes();

assertEquals(bytes1, bytes2);

In Node.js, this also doesn’t work:

import assert from "node:assert/strict";

assert.deepStrictEqual(new Blob(["foo"]), new Blob(["foo"]));

@kt3k, what do you think about adding support for Blob in assertEquals and convert it to asynchronous function?

@kt3k kt3k added wontfix This will not be worked on docs and removed bug Something isn't working labels Nov 25, 2024
@kt3k
Copy link
Member

kt3k commented Nov 25, 2024

@IgorM867 Thanks for looking into this. And I don't think we can fix this as assertEquals is a stable API and we can't make breaking change to it. (Changing assertEquals to async function has too large impact to the ecosystem)

I think the best thing we can do is adding note about it, maybe along with the above example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs wontfix This will not be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants