Skip to main content

Project

Each example separates the action’s source code under src/ from its unit tests under test/, following the same structure across JavaScript and TypeScript projects.
/
src
test

Action

The following Post Login action imports a custom module to fetch the user’s roles from an external service and sets them as a custom claim on the access token, denying access if the module call fails.
test-an-action-module.js
The action requires an Action Module named my-module, which fetches the roles from an external service:
my-module.js

Unit Test

The unit tests load the action alongside the custom module and mock fetch to verify roles are set on success, and that access is denied when the external service returns an error status or the request fails with a network error.
test-an-action-module.spec.js
Add the test dependencies to package.json:
package.json
Configure jsconfig.json so the actions: import alias resolves to src/:
jsconfig.json
test-an-action-module.spec.js
Add the test dependencies to package.json:
package.json
Configure Mocha with .mocharc.json:
.mocharc.json
Configure jsconfig.json so the actions: import alias resolves to src/:
jsconfig.json
test-an-action-module.spec.js
Add the test dependencies to package.json:
package.json
Configure jsconfig.json so the actions: import alias resolves to src/:
jsconfig.json