Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 1.15 KB

generateMockSensitiveObjectId.md

File metadata and controls

31 lines (20 loc) · 1.15 KB

elections-cpl.api.hscc.bdpa.orgDocs


elections-cpl.api.hscc.bdpa.org / lib/mongo-common / generateMockSensitiveObjectId

Function: generateMockSensitiveObjectId()

generateMockSensitiveObjectId(): ObjectId

Calls new ObjectId(...) explicitly passing mockDateNowMs as the inception time, which is the same thing that ObjectId does internally with the real Date.now.

This should only be used in modules with import side-effects that execute before useMockDateNow is called later in downstream code. If you are unsure, you probably don't need to use this function and should just call new ObjectId() instead.

The point of this function is to avoid race conditions when mocking parts of the Date object that sometimes resulted in later calls to ObjectId generating IDs that were less than the IDs generated before it.

Returns

ObjectId

Source

lib/mongo-common/index.ts:107