-
Notifications
You must be signed in to change notification settings - Fork 2
Frontend Testing Guide
This is a guide to testing in our current test environment. For more information on testing, in general, please check out the appendix
Main purpose is for end-to-end testing.
Create a Cypress test when testing UX critical flows such as:
- App signup/signin
- Subscription and payment
- Core functionality like the essay editor
- if you want to test the presence of a UI element, use a component test
- if you want to test whether your button caused data to update, test the reducer
- if you want to test whether interacting with your element triggered the correct action, test the action creator
- Cypress tests can be placed
ejb/frontend/cypress/integration
- Our cypress tests are organised in different folders based on
roles
and specificlti
institutions
Feature description | Directory to place test file |
---|---|
Feature created for educators
|
ejb/frontend/cypress/integration/educator |
Feature affects users with any role | ejb/frontend/cypress/integration/global |
bin/run_cypress
We use Jest for unit testing certain things in our code:
- action creators
- reducers
- component UI
cd frontend
yarn test
File to test | Test file name | Placement of test file |
---|---|---|
/features/main_dashboard/actions.js | /features/main_dashboard/actions.unit.test.js | right next to file to test
|
/features/main_dashboard/reducers.js | /features/main_dashboard/reducers.unit.test.js | right next to file to test
|
/components/datagrid/Datagrid.js | /components/datagrid/Datagrid.unit.test.js | right next to file to test
|
From the Docs:
When testing action creators, we want to test whether the correct action creator was called and also whether the right action was returned
- Spike PR to reference.
- Testing docs: https://redux.js.org/recipes/writing-tests#action-creators
A reducer should return the new state after applying the action to the previous state, and that's the behavior tested
- Spike PR
- Testing docs: https://redux.js.org/recipes/writing-tests#reducers
We use shallow rendering of components
and snapshots
to test UI elements.
A connected component is one that is output from the connect
function of the react-redux
library. In order to test the unwrapped component, you must first export it on it's own.
- Spike PR
- Docs for
connect
: https://react-redux.js.org/api/connect
- Four-Phase Test by Thoughtbot