Actions Unit Test - Auth0 Docs

Documentation Index

Fetch the complete documentation index at: /llms.txt

Use this file to discover all available pages before exploring further.

Using the @auth0/actions NPM package, you can write unit tests for your Actions and run them locally, in version control, or in a CI/CD process, catching issues before they reach your Auth0 tenant.

How it works

Follow the installation and import guidelines described at: How Actions NPM works. To unit test an Action, you must mock the event and api objects that your Action function receives. You can create these mocks using the TypeScript definitions included in auth0/actions, which ensures your tests accurately reflect the production environment. Testing frameworks like Jest are ideal for managing mocking and functionality.

Examples

[Unit Test an Action

Unit tests for a Post Login action that sets a user's roles as a custom ID token claim, denying access when no roles are present, using Jest, Mocha, and Node.js Test Runner in JavaScript and TypeScript.](/content/docs/customize/actions/unit-test/test-an-action/index.html)

[Unit Test an Action That Uses a Module

Unit tests for a Post Login action that fetches user roles from an external service through a custom module and sets them as an access token claim, denying access on failure, using Jest, Mocha, and Node.js Test Runner in JavaScript and TypeScript.](/content/docs/customize/actions/unit-test/test-an-action-module/index.html)

[Unit Test an Action's Dependencies

Unit tests for a Pre User Registration action that blocks a forbidden email domain and validates a submitted full name before storing it and a generated identifier in user and app metadata, using Jest, Mocha, and Node.js Test Runner in JavaScript and TypeScript.](/content/docs/customize/actions/unit-test/mock-dependencies/index.html)

[Unit Test an Action That Renders a Form

Unit tests for a Post Login action that renders a marketing consent Form and stores the submitted answer, denying access when no answer is submitted, using Jest, Mocha, and Node.js Test Runner in JavaScript and TypeScript.](/content/docs/customize/actions/unit-test/mock-form-render/index.html)

[Unit Test an Action That Redirects the User

Unit tests for a Password Reset Post Challenge action that redirects high-risk users for identity verification and validates the returned token before continuing, using Jest, Mocha, and Node.js Test Runner in JavaScript and TypeScript.](/content/docs/customize/actions/unit-test/mock-redirects/index.html)