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 renders a marketing consent Form to users who haven’t answered it yet, then handles the submitted response on the following login attempt: denying access if the Form was skipped, or storing the consent choice in user_metadata otherwise.
mock-form-render.js

Unit Test

The unit tests mock the event and api objects to verify the Form renders only when consent hasn’t been answered, and that both accepted and declined consent submissions are stored correctly while missing submissions are denied.
mock-form-render.spec.js
Add the test dependencies to package.json:
package.json
Configure jsconfig.json so the actions: import alias resolves to src/:
jsconfig.json
mock-form-render.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
mock-form-render.spec.js
Add the test dependencies to package.json:
package.json
Configure jsconfig.json so the actions: import alias resolves to src/:
jsconfig.json