Skip to content

Commit fd0a5a4

Browse files
author
Grace Chong
committed
test: remove .only and add back constructor logic
1 parent 34c727c commit fd0a5a4

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

src/objectid.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ export class ObjectId {
5757
if ('toHexString' in id && typeof id.toHexString === 'function') {
5858
this[kId] = Buffer.from(id.toHexString(), 'hex');
5959
} 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;
6361
}
6462
} else if (id == null || typeof id === 'number') {
6563
// The most common use case (blank id, new objectId instance)

test/node/object_id_tests.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const BSON = require('../register-bson');
55
const util = require('util');
66
const ObjectId = BSON.ObjectId;
77

8-
describe.only('ObjectId', function () {
8+
describe('ObjectId', function () {
99
/**
1010
* @ignore
1111
*/
@@ -48,16 +48,6 @@ describe.only('ObjectId', function () {
4848
expect(() => new ObjectId(objectIdLike)).to.throw(TypeError);
4949
});
5050

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-
6151
it('should correctly create ObjectId from number', function () {
6252
expect(() => new ObjectId(42)).to.not.throw();
6353
expect(() => new ObjectId(0x2a)).to.not.throw();

0 commit comments

Comments
 (0)