API reference@evolu/commonTest › testCreateId

function testCreateId(): TestCreateId;

Defined in: packages/common/src/Test.ts:54

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 {
  assertEqual,
  assertType,
  testCreateId,
  type Brand,
  type Id,
} from "@evolu/common";

const createId = testCreateId();

const callbackId = createId();
const secondCallbackId = createId();
const todoId = createId<"Todo">();
assertEqual(new Set([callbackId, secondCallbackId, todoId]).size, 3);

const replayCreateId = testCreateId();
assertEqual(replayCreateId(), callbackId);
assertType<Id & Brand<"Todo">, typeof todoId>();