@@ -362,54 +362,90 @@ describe('Find Cursor', function () {
362
362
} ) ;
363
363
} ) ;
364
364
365
- describe . only ( 'next + Symbol.asyncIterator()' , function ( ) {
365
+ describe ( 'next + Symbol.asyncIterator()' , function ( ) {
366
366
let client ;
367
367
let collection ;
368
+ let cursor ;
368
369
369
- before ( async function ( ) {
370
+ beforeEach ( async function ( ) {
370
371
client = this . configuration . newClient ( ) ;
371
372
await client . connect ( ) ;
372
373
collection = client . db ( 'next-symbolasynciterator' ) . collection ( 'bar' ) ;
373
374
await collection . deleteMany ( { } , { writeConcern : { w : 'majority' } } ) ;
374
375
await collection . insertMany ( [ { a : 1 } , { a : 2 } ] , { writeConcern : { w : 'majority' } } ) ;
375
376
} ) ;
376
377
377
- after ( async function ( ) {
378
+ afterEach ( async function ( ) {
379
+ await cursor . close ( ) ;
378
380
await client . close ( ) ;
379
381
} ) ;
380
382
381
- // fails
382
- it ( 'allows combining iteration modes' , async function ( ) {
383
- let count = 0 ;
384
- const cursor = collection . find ( ) . map ( doc => {
385
- count ++ ;
386
- return doc ;
383
+ context ( 'when all documents are retrieved in the first batch' , function ( ) {
384
+ it ( 'allows combining iteration modes' , async function ( ) {
385
+ let count = 0 ;
386
+ cursor = collection . find ( ) . map ( doc => {
387
+ count ++ ;
388
+ return doc ;
389
+ } ) ;
390
+
391
+ await cursor . next ( ) ;
392
+ for await ( const _ of cursor ) {
393
+ /* empty */
394
+ }
395
+
396
+ expect ( count ) . to . equal ( 2 ) ;
387
397
} ) ;
388
398
389
- await cursor . next ( ) ;
390
- for await ( const _ of cursor ) {
391
- /* empty */
392
- }
399
+ it ( 'works with next + next() loop' , async function ( ) {
400
+ let count = 0 ;
401
+ cursor = collection . find ( ) . map ( doc => {
402
+ count ++ ;
403
+ return doc ;
404
+ } ) ;
405
+
406
+ await cursor . next ( ) ;
407
+
408
+ let doc ;
409
+ while ( ( doc = ( await cursor . next ( ) ) && doc != null ) ) {
410
+ /** empty */
411
+ }
393
412
394
- expect ( count ) . to . equal ( 2 ) ;
413
+ expect ( count ) . to . equal ( 2 ) ;
414
+ } ) ;
395
415
} ) ;
396
416
397
- // passes
398
- it ( 'works with next + next() loop' , async function ( ) {
399
- let count = 0 ;
400
- const cursor = collection . find ( ) . map ( doc => {
401
- count ++ ;
402
- return doc ;
417
+ context ( 'when there are documents are not retrieved in the first batch' , function ( ) {
418
+ it ( 'allows combining iteration modes' , async function ( ) {
419
+ let count = 0 ;
420
+ cursor = collection . find ( { } , { batchSize : 1 } ) . map ( doc => {
421
+ count ++ ;
422
+ return doc ;
423
+ } ) ;
424
+
425
+ await cursor . next ( ) ;
426
+ for await ( const _ of cursor ) {
427
+ /* empty */
428
+ }
429
+
430
+ expect ( count ) . to . equal ( 2 ) ;
403
431
} ) ;
404
432
405
- await cursor . next ( ) ;
433
+ it ( 'works with next + next() loop' , async function ( ) {
434
+ let count = 0 ;
435
+ cursor = collection . find ( { } , { batchSize : 1 } ) . map ( doc => {
436
+ count ++ ;
437
+ return doc ;
438
+ } ) ;
406
439
407
- let doc ;
408
- while ( ( doc = ( await cursor . next ( ) ) && doc != null ) ) {
409
- /** empty */
410
- }
440
+ await cursor . next ( ) ;
411
441
412
- expect ( count ) . to . equal ( 2 ) ;
442
+ let doc ;
443
+ while ( ( doc = ( await cursor . next ( ) ) && doc != null ) ) {
444
+ /** empty */
445
+ }
446
+
447
+ expect ( count ) . to . equal ( 2 ) ;
448
+ } ) ;
413
449
} ) ;
414
450
} ) ;
415
451
} ) ;
0 commit comments