@@ -45,12 +45,24 @@ describe('Collection (#findOneAnd...)', function () {
45
45
await client ?. close ( ) ;
46
46
} ) ;
47
47
48
- it ( 'returns the deleted document' , async function ( ) {
49
- const result = await collection . findOneAndDelete (
50
- { a : 1 } ,
51
- { includeResultMetadata : false }
52
- ) ;
53
- expect ( result . b ) . to . equal ( 1 ) ;
48
+ context ( 'when there is a match' , function ( ) {
49
+ it ( 'returns the deleted document' , async function ( ) {
50
+ const result = await collection . findOneAndDelete (
51
+ { a : 1 } ,
52
+ { includeResultMetadata : false }
53
+ ) ;
54
+ expect ( result . b ) . to . equal ( 1 ) ;
55
+ } ) ;
56
+ } ) ;
57
+
58
+ context ( 'when there is no match' , function ( ) {
59
+ it ( 'returns null' , async function ( ) {
60
+ const result = await collection . findOneAndDelete (
61
+ { a : 2 } ,
62
+ { includeResultMetadata : false }
63
+ ) ;
64
+ expect ( result ) . to . equal ( null ) ;
65
+ } ) ;
54
66
} ) ;
55
67
} ) ;
56
68
@@ -179,13 +191,26 @@ describe('Collection (#findOneAnd...)', function () {
179
191
await client ?. close ( ) ;
180
192
} ) ;
181
193
182
- it ( 'returns the modified document' , async function ( ) {
183
- const result = await collection . findOneAndUpdate (
184
- { a : 1 } ,
185
- { $set : { a : 1 } } ,
186
- { includeResultMetadata : false }
187
- ) ;
188
- expect ( result . b ) . to . equal ( 1 ) ;
194
+ context ( 'when there is a match' , function ( ) {
195
+ it ( 'returns the modified document' , async function ( ) {
196
+ const result = await collection . findOneAndUpdate (
197
+ { a : 1 } ,
198
+ { $set : { a : 1 } } ,
199
+ { includeResultMetadata : false }
200
+ ) ;
201
+ expect ( result . b ) . to . equal ( 1 ) ;
202
+ } ) ;
203
+ } ) ;
204
+
205
+ context ( 'when there is no match' , function ( ) {
206
+ it ( 'returns null' , async function ( ) {
207
+ const result = await collection . findOneAndUpdate (
208
+ { a : 2 } ,
209
+ { $set : { a : 1 } } ,
210
+ { includeResultMetadata : false }
211
+ ) ;
212
+ expect ( result ) . to . equal ( null ) ;
213
+ } ) ;
189
214
} ) ;
190
215
} ) ;
191
216
@@ -344,13 +369,26 @@ describe('Collection (#findOneAnd...)', function () {
344
369
await client ?. close ( ) ;
345
370
} ) ;
346
371
347
- it ( 'returns the replaced document' , async function ( ) {
348
- const result = await collection . findOneAndReplace (
349
- { a : 1 } ,
350
- { a : 1 } ,
351
- { includeResultMetadata : false }
352
- ) ;
353
- expect ( result . b ) . to . equal ( 1 ) ;
372
+ context ( 'when there is a match' , function ( ) {
373
+ it ( 'returns the replaced document' , async function ( ) {
374
+ const result = await collection . findOneAndReplace (
375
+ { a : 1 } ,
376
+ { a : 1 } ,
377
+ { includeResultMetadata : false }
378
+ ) ;
379
+ expect ( result . b ) . to . equal ( 1 ) ;
380
+ } ) ;
381
+ } ) ;
382
+
383
+ context ( 'when there is no match' , function ( ) {
384
+ it ( 'returns null' , async function ( ) {
385
+ const result = await collection . findOneAndReplace (
386
+ { a : 2 } ,
387
+ { a : 1 } ,
388
+ { includeResultMetadata : false }
389
+ ) ;
390
+ expect ( result ) . to . equal ( null ) ;
391
+ } ) ;
354
392
} ) ;
355
393
} ) ;
356
394
0 commit comments