Skip to content

Commit d7018a0

Browse files
committed
Avoid uncaught exception in 'to satisfy' when the diff is only in properties with symbol keys
1 parent f0fa1b7 commit d7018a0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Diff for: lib/makePromise.js

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ function extractPromisesFromObject(obj) {
9494
Object.keys(obj).forEach((key) => {
9595
promises.push(...extractPromisesFromObject(obj[key]));
9696
});
97+
Object.getOwnPropertySymbols(obj).forEach((key) => {
98+
promises.push(...extractPromisesFromObject(obj[key]));
99+
});
97100
return promises;
98101
}
99102
return [];

Diff for: test/types/Symbol-type.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,31 @@ if (
113113
'}'
114114
);
115115
});
116+
117+
describe('when only symbol properties differ', function () {
118+
// Regression test for not looping over Object.getOwnPropertySymbols(obj)
119+
// in expect.promise.{any,all,settle} when an object is passed:
120+
it('should error and include the Symbol properties in the diff', () => {
121+
const a = {};
122+
a[symbolA] = 'foo';
123+
const b = {};
124+
b[symbolA] = 'bar';
125+
expect(
126+
function () {
127+
expect(a, 'to satisfy', b);
128+
},
129+
'to throw',
130+
"expected { [Symbol('a')]: 'foo' } to satisfy { [Symbol('a')]: 'bar' }\n" +
131+
'\n' +
132+
'{\n' +
133+
" [Symbol('a')]: 'foo' // should equal 'bar'\n" +
134+
' //\n' +
135+
' // -foo\n' +
136+
' // +bar\n' +
137+
'}'
138+
);
139+
});
140+
});
116141
});
117142
});
118143
}

0 commit comments

Comments
 (0)