@@ -14,7 +14,6 @@ import {
1414 LEGACY_HELLO_COMMAND ,
1515 List ,
1616 matchesParentDomain ,
17- maybeCallback ,
1817 MongoDBCollectionNamespace ,
1918 MongoDBNamespace ,
2019 MongoRuntimeError ,
@@ -853,96 +852,6 @@ describe('driver utils', function () {
853852 } ) ;
854853 } ) ;
855854
856- describe ( 'maybeCallback()' , ( ) => {
857- it ( 'should accept two arguments' , ( ) => {
858- expect ( maybeCallback ) . to . have . lengthOf ( 2 ) ;
859- } ) ;
860-
861- describe ( 'when handling an error case' , ( ) => {
862- it ( 'should pass the error to the callback provided' , done => {
863- const superPromiseRejection = Promise . reject ( new Error ( 'fail' ) ) ;
864- const result = maybeCallback (
865- ( ) => superPromiseRejection ,
866- ( error , result ) => {
867- try {
868- expect ( result ) . to . not . exist ;
869- expect ( error ) . to . be . instanceOf ( Error ) ;
870- return done ( ) ;
871- } catch ( assertionError ) {
872- return done ( assertionError ) ;
873- }
874- }
875- ) ;
876- expect ( result ) . to . be . undefined ;
877- } ) ;
878-
879- it ( 'should return the rejected promise to the caller when no callback is provided' , async ( ) => {
880- const superPromiseRejection = Promise . reject ( new Error ( 'fail' ) ) ;
881- const returnedPromise = maybeCallback ( ( ) => superPromiseRejection , undefined ) ;
882- expect ( returnedPromise ) . to . equal ( superPromiseRejection ) ;
883- // @ts -expect-error: There is no overload to change the return type not be nullish,
884- // and we do not want to add one in fear of making it too easy to neglect adding the callback argument
885- const thrownError = await returnedPromise . catch ( error => error ) ;
886- expect ( thrownError ) . to . be . instanceOf ( Error ) ;
887- } ) ;
888-
889- it ( 'should not modify a rejection error promise' , async ( ) => {
890- class MyError extends Error { }
891- const driverError = Object . freeze ( new MyError ( ) ) ;
892- const rejection = Promise . reject ( driverError ) ;
893- // @ts -expect-error: There is no overload to change the return type not be nullish,
894- // and we do not want to add one in fear of making it too easy to neglect adding the callback argument
895- const thrownError = await maybeCallback ( ( ) => rejection , undefined ) . catch ( error => error ) ;
896- expect ( thrownError ) . to . be . equal ( driverError ) ;
897- } ) ;
898-
899- it ( 'should not modify a rejection error when passed to callback' , done => {
900- class MyError extends Error { }
901- const driverError = Object . freeze ( new MyError ( ) ) ;
902- const rejection = Promise . reject ( driverError ) ;
903- maybeCallback (
904- ( ) => rejection ,
905- error => {
906- try {
907- expect ( error ) . to . exist ;
908- expect ( error ) . to . equal ( driverError ) ;
909- done ( ) ;
910- } catch ( assertionError ) {
911- done ( assertionError ) ;
912- }
913- }
914- ) ;
915- } ) ;
916- } ) ;
917-
918- describe ( 'when handling a success case' , ( ) => {
919- it ( 'should pass the result and undefined error to the callback provided' , done => {
920- const superPromiseSuccess = Promise . resolve ( 2 ) ;
921-
922- const result = maybeCallback (
923- ( ) => superPromiseSuccess ,
924- ( error , result ) => {
925- try {
926- expect ( error ) . to . be . undefined ;
927- expect ( result ) . to . equal ( 2 ) ;
928- done ( ) ;
929- } catch ( assertionError ) {
930- done ( assertionError ) ;
931- }
932- }
933- ) ;
934- expect ( result ) . to . be . undefined ;
935- } ) ;
936-
937- it ( 'should return the resolved promise to the caller when no callback is provided' , async ( ) => {
938- const superPromiseSuccess = Promise . resolve ( 2 ) ;
939- const result = maybeCallback ( ( ) => superPromiseSuccess ) ;
940- expect ( result ) . to . equal ( superPromiseSuccess ) ;
941- expect ( await result ) . to . equal ( 2 ) ;
942- } ) ;
943- } ) ;
944- } ) ;
945-
946855 describe ( 'compareObjectId()' , ( ) => {
947856 const table = [
948857 { oid1 : null , oid2 : null , result : 0 } ,
0 commit comments