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

toEqual does not work with Blob objects #7372

Closed
darkowic opened this issue Nov 15, 2018 · 15 comments
Closed

toEqual does not work with Blob objects #7372

darkowic opened this issue Nov 15, 2018 · 15 comments
Labels

Comments

@darkowic
Copy link

πŸ› Bug Report

not.toEqual throws assertion error for 2 not equal Blob's instances.

  ● test toEqual

    expect(received).not.toEqual(expected)

    Expected value to not equal:
      {Symbol(impl): {"_buffer": {"data": [116, 0, 101, 0, 115, 0, 116, 0, 49, 0], "type": "Buffer"}, "type": "text/plain", Symbol(wrapper): [Circular]}}
    Received:
      {Symbol(impl): {"_buffer": {"data": [116, 0, 101, 0, 115, 0, 116, 0, 50, 0], "type": "Buffer"}, "type": "text/plain", Symbol(wrapper): [Circular]}}

      12 |   const blob1 = arrayBufferToBlob(str2ab('test2'), 'text/plain');
      13 |   const blob2 = arrayBufferToBlob(str2ab('test1'), 'text/plain');
    > 14 |   expect(blob1).not.toEqual(blob2);
         |                     ^
      15 | });

To Reproduce

The test:

it('test toEqual', () => {
  const blob1 = arrayBufferToBlob(str2ab('test2'), 'text/plain');
  const blob2 = arrayBufferToBlob(str2ab('test1'), 'text/plain');
  expect(blob1).not.toEqual(blob2);
});

You can find arrayBufferToBlob and str2ab implementation in the codesandbox.io snippet below.

I have tried with the new toStrictEqual and I receive the same output.

It is worth to note that before upgrade jest to 23 and babel to 7 (from beta 37) it was working for me. So, looks like a regresion in version 23.

Expected behavior

2 different blobs instances are not eqaul.

Link to repl or repo (highly encouraged)

It's not reproduced in codesandox.io but you can see the code - https://codesandbox.io/s/k07x6zpnm3

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 4.13 Ubuntu 18.04.1 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
  Binaries:
    Node: 8.12.0 - ~/.virtualenvs/viewer/bin/node
    Yarn: 1.9.4 - /usr/bin/yarn
    npm: 6.4.1 - ~/.virtualenvs/viewer/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

My settings

  "jest": {
    "collectCoverageFrom": [
      "**/*.{js,jsx}"
    ],
    "moduleDirectories": [
      "node_modules",
      "src"
    ],
    "coverageDirectory": "./reports/coverage",
    "coverageReporters": [
      "text-summary"
    ],
    "moduleNameMapper": {
      ".*\\.(css|less|styl|scss|sass)$": "<rootDir>/internals/mocks/cssModule.js",
      ".*\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/internals/mocks/image.js",
      "imports-loader?.*": "<rootDir>/internals/mocks/importsLoader.js"
    },
    "testRegex": "tests/.*\\.test\\.jsx?$",
    "setupFiles": [
      "<rootDir>/internals/testing/setup.js"
    ],
    "setupTestFrameworkScriptFile": "<rootDir>/internals/testing/setup-test.js",
    "testEnvironment": "jest-environment-jsdom-global",
    "testPathIgnorePatterns": [
      "node_modules.*",
      "/containers/",
      "/build/"
    ],
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ]
  },
@rickhanlonii
Copy link
Member

cc @pedrottimark for interest

@matheusPereiraG
Copy link

I was able to reproduce this. I would be glad to pick this up. Can someone provide me some guidance on how to fix this?

@rickhanlonii
Copy link
Member

@matheuspgINF that would be great! I would start with the matcher code here

@rodrigoramos
Copy link

Any updates on this?

@josejulio
Copy link

Would be nice to be able to test blobs with jest

@rickhanlonii
Copy link
Member

Please feel free to submit a PR for this starting with the code linked above.

@codeinabox
Copy link

I wouldn't mind raising a PR for this if it is something that would be welcome in the core Jest code

@jeysal
Copy link
Contributor

jeysal commented May 5, 2020

I would also like to see this work, but I don't think we can support this in Jest? I believe Blob comes from JSDOM, and they should make sure it doesn't have any visible state differences that equals assertions will notice. Does this also happen with the Node.js assert module?

@codeinabox
Copy link

@jeysal
Copy link
Contributor

jeysal commented May 5, 2020

Then I'm not sure what this is about, Buffers?

@codeinabox
Copy link

Then I'm not sure what this is about, Buffers?

The issue is that you can't simply use === to check that two Blob objects are equal, you need to something like FileReader to read the contents of the Blob and compare that.

@jeysal
Copy link
Contributor

jeysal commented May 6, 2020

The part that I don't understand is if Blobs do not exist in Node.js or in JSDOM, how do you want to compare objects that do not exist using Jest?

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants