22
33const Buffer = require ( 'buffer' ) . Buffer ;
44const BSON = require ( '../register-bson' ) ;
5+ const BSONTypeError = BSON . BSONTypeError ;
56const util = require ( 'util' ) ;
67const ObjectId = BSON . ObjectId ;
78
@@ -33,7 +34,7 @@ describe('ObjectId', function () {
3334
3435 for ( const { input, description } of invalidInputs ) {
3536 it ( `should throw error if ${ description } is passed in` , function ( ) {
36- expect ( ( ) => new ObjectId ( input ) ) . to . throw ( TypeError ) ;
37+ expect ( ( ) => new ObjectId ( input ) ) . to . throw ( BSONTypeError ) ;
3738 } ) ;
3839 }
3940
@@ -44,8 +45,7 @@ describe('ObjectId', function () {
4445 return noArgObjID . toHexString ( ) ;
4546 }
4647 } ;
47-
48- expect ( ( ) => new ObjectId ( objectIdLike ) ) . to . throw ( TypeError ) ;
48+ expect ( ( ) => new ObjectId ( objectIdLike ) ) . to . throw ( BSONTypeError ) ;
4949 } ) ;
5050
5151 it ( 'should correctly create ObjectId from object with valid string id' , function ( ) {
@@ -117,15 +117,15 @@ describe('ObjectId', function () {
117117 const objectNullId = {
118118 id : null
119119 } ;
120- expect ( ( ) => new ObjectId ( objectNumId ) ) . to . throw ( TypeError ) ;
121- expect ( ( ) => new ObjectId ( objectNullId ) ) . to . throw ( TypeError ) ;
120+ expect ( ( ) => new ObjectId ( objectNumId ) ) . to . throw ( BSONTypeError ) ;
121+ expect ( ( ) => new ObjectId ( objectNullId ) ) . to . throw ( BSONTypeError ) ;
122122 } ) ;
123123
124124 it ( 'should throw an error if object with invalid string id is passed in' , function ( ) {
125125 const objectInvalid24HexStr = {
126126 id : 'FFFFFFFFFFFFFFFFFFFFFFFG'
127127 } ;
128- expect ( ( ) => new ObjectId ( objectInvalid24HexStr ) ) . to . throw ( TypeError ) ;
128+ expect ( ( ) => new ObjectId ( objectInvalid24HexStr ) ) . to . throw ( BSONTypeError ) ;
129129 } ) ;
130130
131131 it ( 'should correctly create ObjectId from object with invalid string id and toHexString method' , function ( ) {
@@ -144,7 +144,7 @@ describe('ObjectId', function () {
144144 const objectInvalidBuffer = {
145145 id : Buffer . from ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] )
146146 } ;
147- expect ( ( ) => new ObjectId ( objectInvalidBuffer ) ) . to . throw ( TypeError ) ;
147+ expect ( ( ) => new ObjectId ( objectInvalidBuffer ) ) . to . throw ( BSONTypeError ) ;
148148 } ) ;
149149
150150 it ( 'should correctly create ObjectId from object with invalid Buffer id and toHexString method' , function ( ) {
@@ -185,11 +185,11 @@ describe('ObjectId', function () {
185185 } ) ;
186186
187187 it ( 'should throw error if non-12 byte non-24 hex string passed in' , function ( ) {
188- expect ( ( ) => new ObjectId ( 'FFFFFFFFFFFFFFFFFFFFFFFG' ) ) . to . throw ( TypeError ) ;
189- expect ( ( ) => new ObjectId ( 'thisstringisdefinitelytoolong' ) ) . to . throw ( TypeError ) ;
190- expect ( ( ) => new ObjectId ( 'tooshort' ) ) . to . throw ( TypeError ) ;
191- expect ( ( ) => new ObjectId ( '101010' ) ) . to . throw ( TypeError ) ;
192- expect ( ( ) => new ObjectId ( '' ) ) . to . throw ( TypeError ) ;
188+ expect ( ( ) => new ObjectId ( 'FFFFFFFFFFFFFFFFFFFFFFFG' ) ) . to . throw ( BSONTypeError ) ;
189+ expect ( ( ) => new ObjectId ( 'thisstringisdefinitelytoolong' ) ) . to . throw ( BSONTypeError ) ;
190+ expect ( ( ) => new ObjectId ( 'tooshort' ) ) . to . throw ( BSONTypeError ) ;
191+ expect ( ( ) => new ObjectId ( '101010' ) ) . to . throw ( BSONTypeError ) ;
192+ expect ( ( ) => new ObjectId ( '' ) ) . to . throw ( BSONTypeError ) ;
193193 } ) ;
194194
195195 it ( 'should correctly create ObjectId from 24 hex string' , function ( ) {
@@ -234,7 +234,7 @@ describe('ObjectId', function () {
234234
235235 it ( 'should throw an error if invalid Buffer passed in' , function ( ) {
236236 const a = Buffer . from ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] ) ;
237- expect ( ( ) => new ObjectId ( a ) ) . to . throw ( TypeError ) ;
237+ expect ( ( ) => new ObjectId ( a ) ) . to . throw ( BSONTypeError ) ;
238238 } ) ;
239239
240240 it ( 'should correctly allow for node.js inspect to work with ObjectId' , function ( done ) {
@@ -260,11 +260,11 @@ describe('ObjectId', function () {
260260 const characterCodesLargerThan256 = 'abcdefŽhijkl' ;
261261 const length12Not12Bytes = '🐶🐶🐶🐶🐶🐶' ;
262262 expect ( ( ) => new ObjectId ( characterCodesLargerThan256 ) . toHexString ( ) ) . to . throw (
263- TypeError ,
263+ BSONTypeError ,
264264 'Argument passed in must be a string of 12 bytes'
265265 ) ;
266266 expect ( ( ) => new ObjectId ( length12Not12Bytes ) . id ) . to . throw (
267- TypeError ,
267+ BSONTypeError ,
268268 'Argument passed in must be a string of 12 bytes'
269269 ) ;
270270 } ) ;
0 commit comments