11'use strict' ;
2- const { assert : test } = require ( '../shared' ) ;
2+ const { assert : test , filterForCommands } = require ( '../shared' ) ;
33const { expect } = require ( 'chai' ) ;
44const sinon = require ( 'sinon' ) ;
55const { setTimeout } = require ( 'timers' ) ;
6- const { Code, ObjectId, Long, Binary, ReturnDocument, CursorResponse } = require ( '../../mongodb' ) ;
6+ const {
7+ Code,
8+ ObjectId,
9+ Long,
10+ Binary,
11+ ReturnDocument,
12+ CursorResponse,
13+ MongoServerError
14+ } = require ( '../../mongodb' ) ;
715
816describe ( 'Find' , function ( ) {
917 /** @type (import('../../mongodb').MongoClient */
@@ -499,7 +507,13 @@ describe('Find', function () {
499507
500508 it ( 'shouldCorrectlyPerformFindsWithHintTurnedOn' , async function ( ) {
501509 const configuration = this . configuration ;
502- client = configuration . newClient ( configuration . writeConcernMax ( ) , { maxPoolSize : 1 } ) ;
510+ client = configuration . newClient ( configuration . writeConcernMax ( ) , {
511+ monitorCommands : true
512+ } ) ;
513+
514+ const finds = [ ] ;
515+ client . on ( 'commandStarted' , filterForCommands ( 'find' , finds ) ) ;
516+
503517 await client . connect ( ) ;
504518
505519 const db = client . db ( configuration . db ) ;
@@ -515,30 +529,16 @@ describe('Find', function () {
515529 . find ( { a : 1 } , { hint : 'a' } )
516530 . toArray ( )
517531 . catch ( e => e )
518- ) . to . be . instanceOf ( Error ) ;
532+ ) . to . be . instanceOf ( MongoServerError ) ;
533+ expect ( finds [ 0 ] . command . hint ) . to . equal ( 'a' ) ;
519534
520535 // Test with hint as array
521536 expect ( await collection . find ( { a : 1 } , { hint : [ 'a' ] } ) . toArray ( ) ) . to . have . lengthOf ( 1 ) ;
537+ expect ( finds [ 1 ] . command . hint ) . to . deep . equal ( { a : 1 } ) ;
522538
523539 // Test with hint as object
524540 expect ( await collection . find ( { a : 1 } , { hint : { a : 1 } } ) . toArray ( ) ) . to . have . lengthOf ( 1 ) ;
525-
526- // Modify hints
527- collection . hint = 'a_1' ;
528- expect ( collection . hint ) . to . equal ( 'a_1' ) ;
529- expect ( await collection . find ( { a : 1 } ) . toArray ( ) ) . to . have . lengthOf ( 1 ) ;
530-
531- collection . hint = [ 'a' ] ;
532- expect ( collection . hint [ 'a' ] ) . to . equal ( 1 ) ;
533- expect ( await collection . find ( { a : 1 } ) . toArray ( ) ) . to . have . lengthOf ( 1 ) ;
534-
535- collection . hint = { a : 1 } ;
536- expect ( collection . hint [ 'a' ] ) . to . equal ( 1 ) ;
537- expect ( await collection . find ( { a : 1 } ) . toArray ( ) ) . to . have . lengthOf ( 1 ) ;
538-
539- collection . hint = null ;
540- expect ( collection . hint ) . to . be . undefined ;
541- expect ( await collection . find ( { a : 1 } ) . toArray ( ) ) . to . have . lengthOf ( 1 ) ;
541+ expect ( finds [ 2 ] . command . hint ) . to . deep . equal ( { a : 1 } ) ;
542542 } ) ;
543543
544544 it ( 'shouldCorrectlyPerformFindByObjectId' , {
0 commit comments