Skip to main content

Getting started

Running tests!

Current repositories this applies to:

  • saas-client

Project Testing Structure

├── jest.config.js
├── src
│   └── test
│   └── react-testing-library
│   ├── mocks
│   │   ├── ...
│   │   ├── mocks.js
│   │   └── styleMock.js
│   ├── test
│ │ ├── ...
│   └── utils
│   ├── ApiRequest.js
│   ├── RESTHelper.js
│   ├── setupTest.js
│   └── test-utils.js
  • jest.config.js - Main jest configuration file
  • src/test/react-testing-library/mocks - Mock directory for global mocking
  • src/test/react-testing-library/test - Directory for all jest tests
  • src/test/react-testing-library/utils - Utils directory for jest helpers

VS Code setup

Please install the vscode-jest plugin

Open vscode workspace settings (JSON)

Paste the following:

.vscode/settings.json
{
"jest.rootPath": "",
"jest.jestCommandLine": "npm run test-unit-jest --"
}

This makes the default runner command too use test-unit-jest vs npm run test which would run both karma and jest.

You should now see the following icon in your sidebar

Testing Icon vscode

As well as this in your bottom status bar

Testing status bar vscode

The eye icon beside Jest: indicates Jest is watching for changes and will automatically re-run tests depending on the git diff. Beside the Jest-WS indicates how many tests, passed, failed and tests that have yet to run: unknown

You will now have a nice hierarchy of all the test statuses in the sidebar:

Testing Panel vscode