File tree Expand file tree Collapse file tree 2 files changed +2
-14
lines changed Expand file tree Collapse file tree 2 files changed +2
-14
lines changed Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ export class ObjectId {
57
57
if ( 'toHexString' in id && typeof id . toHexString === 'function' ) {
58
58
this [ kId ] = Buffer . from ( id . toHexString ( ) , 'hex' ) ;
59
59
} else {
60
- throw new TypeError (
61
- 'Object passed in does not have toHexString() function'
62
- ) ;
60
+ this [ kId ] = typeof id . id === 'string' ? Buffer . from ( id . id ) : id . id ;
63
61
}
64
62
} else if ( id == null || typeof id === 'number' ) {
65
63
// The most common use case (blank id, new objectId instance)
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ const BSON = require('../register-bson');
5
5
const util = require ( 'util' ) ;
6
6
const ObjectId = BSON . ObjectId ;
7
7
8
- describe . only ( 'ObjectId' , function ( ) {
8
+ describe ( 'ObjectId' , function ( ) {
9
9
/**
10
10
* @ignore
11
11
*/
@@ -48,16 +48,6 @@ describe.only('ObjectId', function () {
48
48
expect ( ( ) => new ObjectId ( objectIdLike ) ) . to . throw ( TypeError ) ;
49
49
} ) ;
50
50
51
- it ( 'should throw error if object without toHexString function is passed in' , function ( ) {
52
- var tmp = new ObjectId ( ) ;
53
- var objectIdLike = {
54
- id : tmp . id
55
- } ;
56
- objectIdLike . id . toHexString = null ;
57
-
58
- expect ( ( ) => new ObjectId ( objectIdLike ) . toHexString ( ) ) . to . throw ( TypeError ) ;
59
- } ) ;
60
-
61
51
it ( 'should correctly create ObjectId from number' , function ( ) {
62
52
expect ( ( ) => new ObjectId ( 42 ) ) . to . not . throw ( ) ;
63
53
expect ( ( ) => new ObjectId ( 0x2a ) ) . to . not . throw ( ) ;
You can’t perform that action at this time.
0 commit comments