Skip to main content
The recommended method of testing API Extension applications is to use the Action Simulator in conjunction with thorough integration testing.

Action Simulator

The Action Simulator produces a mock context that you can utilize in your API Extension test files to simulate data from Kibo and verify that your functions run as expected. You can view the Action Simulator library in the node_modules/mozu-action-simulator directory of your project folder. The simulator provides:
  • Test fixtures for your actions that you can leverage to create data for your tests.
  • Access to the assert module, which helps you devise assertion tests to determine whether your logic executes as expected.
To use the simulator:
  1. Open the test file that corresponds to one of the actions you have scaffolded. Test files are located in the assets/test directory.
  2. Require the mozu-action-simulatorpackage in your test file. For example:
  3. Access simulator features, such as Simulator.context() or Simulator.assert, to facilitate writing tests for your function.

Example of Testing with the Simulator

In this example, the embedded.commerce.carts.addItem.before action has been designed to check whether an item added to the cart has a ‘Hazardous’ product attribute. If the new item is hazardous and the cart already contains an existing hazardous item, the action removes the new item from the cart. The following code block demonstrates how you would test this action within its corresponding test file using the Action Simulator. assets/test/embedded.commerce.carts.addItem.before.t.js