docbrown/docs/tests/frontend-tests.md
2020-05-21 11:46:57 -04:00

1.3 KiB

title
Frontend Tests

Frontend Tests

The test code is located within the same directory as each component, inside a __tests__ directory.

$ tree app/javascript/article-form -L 1
app/javascript/article-form
├── __tests__
└── articleForm.jsx

The testing library being used is Jest.

You can run those tests with:

npm run test

or

yarn test

Should you want to view only a single jest test, you can run:

npx jest app/javascript/<path-to-file>

To troubleshoot any of your jest test files, add a debugger and run:

node --inspect node_modules/.bin/jest --watch --runInBand <path-to-file>

You can read more about troubleshooting here.

At the end of the test's execution, you will see the code coverage for the Preact components in our codebase.

If tests require utility modules, create them in a utilities folder under the __tests__ folder. Jest is configured to not treat the utilities folder as a test suite.