diff options
author | Winnie Hellmann <winnie@gitlab.com> | 2019-05-21 18:38:27 +0000 |
---|---|---|
committer | Evan Read <eread@gitlab.com> | 2019-05-21 18:38:27 +0000 |
commit | e1b31627396f12e84bd663efcd890d5f8e4cf195 (patch) | |
tree | 9c58b6874bef3e61862bb97df9c736d5b8d78fa8 | |
parent | bb6d1572a361a510379eac00f56f2386d1d1850c (diff) | |
download | gitlab-ce-e1b31627396f12e84bd663efcd890d5f8e4cf195.tar.gz |
Document the differences between Karma and Jest setup
-rw-r--r-- | doc/development/testing_guide/frontend_testing.md | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/doc/development/testing_guide/frontend_testing.md b/doc/development/testing_guide/frontend_testing.md index 9bd99e80357..58d6f08954d 100644 --- a/doc/development/testing_guide/frontend_testing.md +++ b/doc/development/testing_guide/frontend_testing.md @@ -15,10 +15,8 @@ information on general testing practices at GitLab. ## Jest -GitLab has started to migrate tests to the [Jest](https://jestjs.io) -testing framework. You can read a [detailed evaluation](https://gitlab.com/gitlab-org/gitlab-ce/issues/49171) -of Jest compared to our use of Karma and Jasmine. In summary, it will allow us -to improve the performance and consistency of our frontend tests. +We have started to migrate frontend tests to the [Jest](https://jestjs.io) testing framework (see also the corresponding +[epic](https://gitlab.com/groups/gitlab-org/-/epics/895)). Jest tests can be found in `/spec/frontend` and `/ee/spec/frontend` in EE. @@ -26,6 +24,17 @@ It is not yet a requirement to use Jest. You can view the [epic](https://gitlab.com/groups/gitlab-org/-/epics/873) of issues we need to solve before being able to use Jest for all our needs. +### Differences to Karma + +- Jest runs in a Node.js environment, not in a browser. Support for running Jest tests in a browser [is planned](https://gitlab.com/gitlab-org/gitlab-ce/issues/58205). +- Because Jest runs in a Node.js environment, it uses [jsdom](https://github.com/jsdom/jsdom) by default. +- All calls to `setTimeout` and `setInterval` are mocked away. See also [Jest Timer Mocks](https://jestjs.io/docs/en/timer-mocks). +- `rewire` is not required because Jest supports mocking modules. See also [Manual Mocks](https://jestjs.io/docs/en/manual-mocks). +- The following will cause tests to fail in Jest: + - Unmocked requests. + - Unhandled Promise rejections. + - Calls to `console.warn`, including warnings from libraries like Vue. + ### Debugging Jest tests Running `yarn jest-debug` will run Jest in debug mode, allowing you to debug/inspect as described in the [Jest docs](https://jestjs.io/docs/en/troubleshooting#tests-are-failing-and-you-don-t-know-why). |