@glinr/theauth-test-utils provides factories, mock servers, and assertion helpers so you can test auth-dependent code without a real database or network.
Install
Factories
Factory functions create realistic mock entities with sensible defaults. Pass overrides for any fields relevant to the test.Mock auth server
createMockAuthServer returns an in-memory AuthAdapter implementation with zero network or database calls. Use it in server-side unit tests that exercise code paths calling resolveUser, getUser, or syncUser.
Per-request user override
Set thex-mock-theauth-user-id header on a Request to override the active user for that specific request only, without calling setActiveUser:
Cleanup
Assertions
Three typed assertion helpers narrowActionResult<T> (the result type used by @glinr/theauth-react, where a failure carries an error string) and throw descriptive errors on failure.
Mock React provider
For component tests,MockTheAuthProvider replaces <TheAuthProvider> with fixed values. It accepts user, session, isAuthenticated, isLoading, and optional signIn, signUp, signOut, and refresh overrides. The actions default to vi.fn() spies, so you can assert on calls.
The mock server itself has no dependencies. It matches the
AuthAdapter interface structurally, so TypeScript will accept it anywhere an AuthAdapter is expected. The package entry point also exports MockTheAuthProvider, which imports vitest, react and @glinr/theauth-react (react and @glinr/theauth-react are optional peer dependencies), so use the package from a Vitest setup.Related
Error codes
How theAuth reports errors.
Database setup
In-memory SQLite for integration tests that need a real database.
Agent identity
Agent creation and permission checking to exercise in integration tests.
Hooks
Lifecycle hooks you can attach to your instance.