@@ -20,7 +20,7 @@ function is42(input) {
20
20
return valIs42 ( input ) || valIs42 ( input . $numberInt ) || valIs42 ( input . $numberLong ) ;
21
21
}
22
22
23
- function generateMatchAndDiffSpecialCase ( key , expectedObj , actualObj , metadata ) {
23
+ function generateMatchAndDiffSpecialCase ( key , expectedObj , actualObj , metadata , isRoot ) {
24
24
const expected = expectedObj [ key ] ;
25
25
const actual = actualObj [ key ] ;
26
26
@@ -44,11 +44,16 @@ function generateMatchAndDiffSpecialCase(key, expectedObj, actualObj, metadata)
44
44
} ;
45
45
}
46
46
47
- const match = ! Object . prototype . hasOwnProperty . call ( actualObj , key ) ;
47
+ // An expected null value is not the same as the value not being present
48
+ // so an exact match is forced here when not at the root level of the
49
+ // object.
50
+ const match = isRoot
51
+ ? ! Object . prototype . hasOwnProperty . call ( actualObj , key )
52
+ : expected === actual ;
48
53
return {
49
54
match,
50
- expected : SYMBOL_DOES_NOT_EXIST ,
51
- actual : match ? SYMBOL_DOES_NOT_EXIST : actual
55
+ expected : expected ,
56
+ actual : actual === undefined ? SYMBOL_DOES_NOT_EXIST : actual
52
57
} ;
53
58
}
54
59
@@ -88,7 +93,7 @@ function generateMatchAndDiffSpecialCase(key, expectedObj, actualObj, metadata)
88
93
// Case lsid - assert that session matches session in session data
89
94
const sessionData = metadata . sessionData ;
90
95
const lsid = sessionData [ expected ] ;
91
- return generateMatchAndDiff ( lsid , actual , metadata ) ;
96
+ return generateMatchAndDiff ( lsid , actual , metadata , false ) ;
92
97
} else if ( key === 'getMore' && expectedIs42 ) {
93
98
// cursorid - explicitly ignore 42 values
94
99
return {
@@ -121,11 +126,11 @@ function generateMatchAndDiffSpecialCase(key, expectedObj, actualObj, metadata)
121
126
} ;
122
127
} else {
123
128
// default
124
- return generateMatchAndDiff ( expected , actual , metadata ) ;
129
+ return generateMatchAndDiff ( expected , actual , metadata , false ) ;
125
130
}
126
131
}
127
132
128
- function generateMatchAndDiff ( expected , actual , metadata ) {
133
+ function generateMatchAndDiff ( expected , actual , metadata , isRoot ) {
129
134
const typeOfExpected = typeof expected ;
130
135
131
136
if ( typeOfExpected === 'object' && expected . _bsontype === 'Int32' && typeof actual === 'number' ) {
@@ -154,7 +159,7 @@ function generateMatchAndDiff(expected, actual, metadata) {
154
159
}
155
160
156
161
return expected
157
- . map ( ( val , idx ) => generateMatchAndDiff ( val , actual [ idx ] , metadata ) )
162
+ . map ( ( val , idx ) => generateMatchAndDiff ( val , actual [ idx ] , metadata , false ) )
158
163
. reduce (
159
164
( ret , value ) => {
160
165
ret . match = ret . match && value . match ;
@@ -168,7 +173,7 @@ function generateMatchAndDiff(expected, actual, metadata) {
168
173
169
174
return Object . keys ( expected ) . reduce (
170
175
( ret , key ) => {
171
- const check = generateMatchAndDiffSpecialCase ( key , expected , actual , metadata ) ;
176
+ const check = generateMatchAndDiffSpecialCase ( key , expected , actual , metadata , isRoot ) ;
172
177
ret . match = ret . match && check . match ;
173
178
ret . expected [ key ] = check . expected ;
174
179
ret . actual [ key ] = check . actual ;
@@ -192,7 +197,7 @@ function matchMongoSpec(chai, utils) {
192
197
193
198
const sessionData = utils . flag ( this , 'testRunnerSessionData' ) ;
194
199
195
- const result = generateMatchAndDiff ( expected , actual , { sessionData } ) ;
200
+ const result = generateMatchAndDiff ( expected , actual , { sessionData } , true ) ;
196
201
197
202
chai . Assertion . prototype . assert . call (
198
203
this ,
0 commit comments