-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Labels
Description
🐛 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