API reference › @evolu/common › Test › testCreateId
function testCreateId(): TestCreateId;
Defined in: packages/common/src/Test.ts:48
Creates a deterministic createId helper.
The returned function mirrors createId, but uses stable test entropy so each call yields the next deterministic pseudo-random id.
Create one helper per test, or per reusable test setup helper such as
setupFoo, so deterministic ids stay local to that setup.
Avoid sharing one helper across a whole test file. Adding an extra createId
call in one test would shift ids used by unrelated tests later in the file.
Example
import { testCreateId, type Brand, type Id } from "@evolu/common";
const createId = testCreateId();
const callbackId = createId();
const secondCallbackId = createId();
const todoId = createId<"Todo">();
expect(new Set([callbackId, secondCallbackId, todoId]).size).toBe(3);
const replayCreateId = testCreateId();
expect(replayCreateId()).toBe(callbackId);
expectTypeOf(todoId).toEqualTypeOf<Id & Brand<"Todo">>();