Functions ships with support for Jest ↗ unit tests. Follow the steps in this guide to get unit testing tools set up for your repository.
By default, Functions includes a unit test located in the test file functions-typescript/src/__tests__/index.ts. You can create test files anywhere in the __tests__ folder.
Example
For example, we may want to test the following function addOne in functions-typescript/src/index.ts:
Copied!
1
2
3
4
5
6
7
8
9
import { Function, Integer } from "@foundry/functions-api";
export class MyFunctions {
@Function()
public addOne(n: Integer): Integer {
return n + 1;
}
}
We can test the function addOne by writing the following test test add one:
Refer to the Jest API ↗ for details about the full testing API available to you.
Running tests
You can run all your tests by clicking on the Test button located on the top right, or run each individual test by clicking on the triangular "Play" button located beside the line number for each test.
When you click Commit, all tests will also run in Checks:
Next steps
Next, learn about the range of options available for testing Functions that interact with the Ontology: