Skip to content

Commit a2433fc

Browse files
committed
[testing] properly compare objects that don't have a constructor
1 parent 5ee9bf2 commit a2433fc

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ const _compare = (a, b, path, message, customCompare) => {
478478
})
479479
break
480480
}
481+
case undefined: // undefined is often set as a constructor for objects
481482
case Object:
482483
if (object.length(a) !== object.length(b)) {
483484
_failMessage(message, 'Objects have a different number of attributes', path)

testing.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const testComparing = _tc => {
3636
map2.set('x', {})
3737
map2.set(98, 'tst')
3838
t.compare(map1, map2, 'compare Maps')
39-
4039
t.describe('The following errors are expected!')
4140
t.fails(() => {
4241
t.compare({ a: 4 }, { b: 5 }, 'childs are not equal')
@@ -114,6 +113,13 @@ export const testComparing = _tc => {
114113
t.fails(() => {
115114
t.compare(new Set([1]), new Set([2])) // childs have different length (array) -- no message
116115
})
116+
t.group('test object with constructor set to `undefined`', () => {
117+
const a = Object.create(null)
118+
const b = Object.create(null)
119+
a.x = 42
120+
b.x = 42
121+
t.compare(a, b)
122+
})
117123
}
118124

119125
export const testFailing = async () => {

0 commit comments

Comments
 (0)