File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -416,7 +416,7 @@ describe('Find Cursor', function () {
416
416
} ) ;
417
417
418
418
context ( 'when there are documents are not retrieved in the first batch' , function ( ) {
419
- it ( 'allows combining iteration modes ' , async function ( ) {
419
+ it ( 'allows combining next() and for await syntax ' , async function ( ) {
420
420
let count = 0 ;
421
421
cursor = collection . find ( { } , { batchSize : 1 } ) . map ( doc => {
422
422
count ++ ;
@@ -432,6 +432,24 @@ describe('Find Cursor', function () {
432
432
expect ( count ) . to . equal ( 2 ) ;
433
433
} ) ;
434
434
435
+ it . only ( 'allows partial iteration with for await syntax and then calling .next()' , async function ( ) {
436
+ let count = 0 ;
437
+ cursor = collection . find ( { } , { batchSize : 2 } ) . map ( doc => {
438
+ count ++ ;
439
+ return doc ;
440
+ } ) ;
441
+
442
+ for await ( const doc of cursor ) {
443
+ console . log ( doc ) ;
444
+ /* empty */
445
+ break ;
446
+ }
447
+
448
+ await cursor . next ( ) ;
449
+
450
+ expect ( count ) . to . equal ( 2 ) ;
451
+ } ) ;
452
+
435
453
it ( 'works with next + next() loop' , async function ( ) {
436
454
let count = 0 ;
437
455
cursor = collection . find ( { } , { batchSize : 1 } ) . map ( doc => {
You can’t perform that action at this time.
0 commit comments