To test your script's logic, create unit tests in script.spec.ts and then run them using the npm test command.
Write the unit tests
In the unit test file (test/script.spec.ts), use as-pect's AssemblyScript API functions to structure your tests and compare results.
Create example objects for your test cases. Each Scripts API has TestHelper classes that you can use to do this.
Each TestHelper class is a builder that has a
.buildWithIDmethod, depending on whether the object needs a unique identifier. For example, a product has an ID, so the
ProductBuilderclass has a
The following example code creates a ProductBuilder to build products with the name
Red Deliciousand a tag named
The following example code uses this same ProductBuilder to create products with different IDs:
To create test cases for configurations, use the Configuration class.
The following example uses a
Configurationobject to test different configuration values:
Run the unit tests
Run the following command:
When the test file runs successfully without any errors, the output looks like the following:
When the test file runs successfully but some of the unit tests fail, the output looks like the following:
When the test file fails, you find an error like the following in the output: