Testing
Adding some unit tests is a great way to ensure that the bindings work as expected. It illustrates how the bindings are supposed to be used and can help to catch regressions.
Testing the bindings
Create a new help in the test
folder with the same name as the module you want to test, followed by _test.res
.
Directorysrc
- DOMAPI.res
DirectoryDOMAPI
- HTMLCanvasElement.res
Directorytests
DirectoryDOMAPI
- HTMLCanvasElement_test.res
Add a small sample of valid code that uses the bindings you’ve changed. Add it to source control and run
If any of the existing tests have different ouput JavaScript, you will see a diff in the output and the test will fail.
Why add tests?
Sometimes adding a test can feel like a bit of a hassle. But we insist that you add tests for the following reasons:
- Documentation: Tests are a form of documentation. They show how the bindings are supposed to be used.
- Regression: Tests help to catch regressions. If a change breaks something, the test will fail.
- Awareness: Tests make you aware of the API you are using. In the future we might trim down the generated bindings to only include the most used APIs. If you have a test, you can be sure that the API is not going away.