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

isEqual() on iterable ignores other properties #8280

Closed
jheeffer opened this issue Apr 6, 2019 · 4 comments · Fixed by #8359
Closed

isEqual() on iterable ignores other properties #8280

jheeffer opened this issue Apr 6, 2019 · 4 comments · Fixed by #8359

Comments

@jheeffer
Copy link

jheeffer commented Apr 6, 2019

🐛 Bug Report

Testing iterable objects with isEqual() ignores other properties on the iterable

To Reproduce

let next = () => ({ value: undefined, done: true });
test('iterable', () => {
    expect({ 
        [Symbol.iterator]: () => ({ next }), 
        data: ['foo'] 
    }).toEqual({ 
        [Symbol.iterator]: () => ({ next }), 
        data: [] 
    })
});

Same behaviour when using the iterator of data property:

let data = ['foo'], data2 = [];
test('foo', () => {
    expect({ 
        [Symbol.iterator]: data[Symbol.iterator], 
        data
    }).toEqual({ 
        [Symbol.iterator]: data2[Symbol.iterator], 
        data: data2
    })
});

both result in

PASS  test/foo.test.js
  ✓ foo (6ms)

Expected behavior

Other properties are evaluated when object is iterable. Like when removing the iterators from above code:

 FAIL  test/foo.test.js
  ✕ foo (14ms)

  ● foo

    expect(received).toEqual(expected)

    Difference:

    - Expected
    + Received

      Object {
    -   "data": Array [],
    +   "data": Array [
    +     "foo",
    +   ],
      }

Link to repl or repo (highly encouraged)

https://repl.it/repls/CaringPrimarySupport

Run npx envinfo --preset jest

Paste the results here:

npx: installed 1 in 1.537s

  System:
    OS: Linux 4.4 Ubuntu 16.04.1 LTS (Xenial Xerus)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  Binaries:
    Node: 8.9.1 - /usr/bin/node
    npm: 6.4.1 - /usr/bin/npm
  npmPackages:
    jest: ^24.7.1 => 24.7.1
@jeysal
Copy link
Contributor

jeysal commented Apr 6, 2019

This reproduces for me, and it's a bug with our custom iterableEquality. With Arrays, it works.

@d7my11
Copy link
Contributor

d7my11 commented Apr 21, 2019

I'll send a PR

@SimenB
Copy link
Member

SimenB commented Feb 24, 2022

@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 Mar 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants