Some background to understand and write tests for the nns-dapp.
Tests are in ./frontend/src/tests
.
$ cd frontend
$ npm test
Tests in frontend/src/tests/lib
and frontend/src/tests/routes
are the unit tests for each component or functions we have.
A simple component test example can be AccountBadge.spec.ts.
On the other hand, check accounts.utils.spec for function testing.
Test in src/tests/workfows
are considered more of integration tests. The main goal is to test whole workflows mocking only the api layer.
For example in CreateSubaccount.spec.ts it renders the Accounts page and performs the actions to create a subaccount.
There are a few rules to consider a test as an integration test:
- Mock only the api layer and authStore.
- Set the stores to any value needed to check the flow you're testing.
- No mocking of services, utils, stores, ...
- Do not use CSS classes as selector.
- Expect calls to the api layer.
All the mocks used in different tests are in frontend/src/tests/mocks
.
Found in frontend/src/tests/utils
.
Tests are found in rs/src/accounts_store/tests.rs
.
$ cd rs
$ cargo test
At the moment we have only unit tests.