moderator-toolbox-nxg-for-reddit / background/handlers/test-helpers

background/handlers/test-helpers

Functions

makeHandlerFinder()

makeHandlerFinder(registerMock): (action) => unknown

Defined in: extension/data/background/handlers/test-helpers.ts:16

Returns a handlerFor function bound to the given registerMessageHandler mock. The returned function finds the handler that was registered for a given action string.

Parameters

registerMock

Mock<Procedure | Constructable>

Returns

(action) => unknown

Example

const registerMessageHandler = vi.hoisted(() => vi.fn());
const handlerFor = makeHandlerFinder(registerMessageHandler);
// In tests:
const handler = handlerFor('toolbox-cache');

mockJwtCookie()

mockJwtCookie(payload): object

Defined in: extension/data/background/handlers/test-helpers.ts:34

Creates a minimal mock browser cookie whose value is a JWT with the given payload. The token is not signed; only the header and payload portions are present.

Parameters

payload

Record<string, unknown>

Returns

object

value

value: string

Example

cookies.get.mockResolvedValue(mockJwtCookie({sub: 't2_user'}));