2
2
3
3
const Buffer = require ( 'buffer' ) . Buffer ;
4
4
const BSON = require ( '../register-bson' ) ;
5
+ const BSONTypeError = BSON . BSONTypeError ;
5
6
const util = require ( 'util' ) ;
6
7
const ObjectId = BSON . ObjectId ;
7
8
@@ -33,7 +34,7 @@ describe('ObjectId', function () {
33
34
34
35
for ( const { input, description } of invalidInputs ) {
35
36
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 ) ;
37
38
} ) ;
38
39
}
39
40
@@ -44,8 +45,7 @@ describe('ObjectId', function () {
44
45
return noArgObjID . toHexString ( ) ;
45
46
}
46
47
} ;
47
-
48
- expect ( ( ) => new ObjectId ( objectIdLike ) ) . to . throw ( TypeError ) ;
48
+ expect ( ( ) => new ObjectId ( objectIdLike ) ) . to . throw ( BSONTypeError ) ;
49
49
} ) ;
50
50
51
51
it ( 'should correctly create ObjectId from object with valid string id' , function ( ) {
@@ -117,15 +117,15 @@ describe('ObjectId', function () {
117
117
const objectNullId = {
118
118
id : null
119
119
} ;
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 ) ;
122
122
} ) ;
123
123
124
124
it ( 'should throw an error if object with invalid string id is passed in' , function ( ) {
125
125
const objectInvalid24HexStr = {
126
126
id : 'FFFFFFFFFFFFFFFFFFFFFFFG'
127
127
} ;
128
- expect ( ( ) => new ObjectId ( objectInvalid24HexStr ) ) . to . throw ( TypeError ) ;
128
+ expect ( ( ) => new ObjectId ( objectInvalid24HexStr ) ) . to . throw ( BSONTypeError ) ;
129
129
} ) ;
130
130
131
131
it ( 'should correctly create ObjectId from object with invalid string id and toHexString method' , function ( ) {
@@ -144,7 +144,7 @@ describe('ObjectId', function () {
144
144
const objectInvalidBuffer = {
145
145
id : Buffer . from ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] )
146
146
} ;
147
- expect ( ( ) => new ObjectId ( objectInvalidBuffer ) ) . to . throw ( TypeError ) ;
147
+ expect ( ( ) => new ObjectId ( objectInvalidBuffer ) ) . to . throw ( BSONTypeError ) ;
148
148
} ) ;
149
149
150
150
it ( 'should correctly create ObjectId from object with invalid Buffer id and toHexString method' , function ( ) {
@@ -185,11 +185,11 @@ describe('ObjectId', function () {
185
185
} ) ;
186
186
187
187
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 ) ;
193
193
} ) ;
194
194
195
195
it ( 'should correctly create ObjectId from 24 hex string' , function ( ) {
@@ -234,7 +234,7 @@ describe('ObjectId', function () {
234
234
235
235
it ( 'should throw an error if invalid Buffer passed in' , function ( ) {
236
236
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 ) ;
238
238
} ) ;
239
239
240
240
it ( 'should correctly allow for node.js inspect to work with ObjectId' , function ( done ) {
@@ -260,11 +260,11 @@ describe('ObjectId', function () {
260
260
const characterCodesLargerThan256 = 'abcdefŽhijkl' ;
261
261
const length12Not12Bytes = '🐶🐶🐶🐶🐶🐶' ;
262
262
expect ( ( ) => new ObjectId ( characterCodesLargerThan256 ) . toHexString ( ) ) . to . throw (
263
- TypeError ,
263
+ BSONTypeError ,
264
264
'Argument passed in must be a string of 12 bytes'
265
265
) ;
266
266
expect ( ( ) => new ObjectId ( length12Not12Bytes ) . id ) . to . throw (
267
- TypeError ,
267
+ BSONTypeError ,
268
268
'Argument passed in must be a string of 12 bytes'
269
269
) ;
270
270
} ) ;
0 commit comments