diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-27 12:10:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-27 12:10:54 +0000 |
commit | 7a20b3758e651fe79032a5165db2208183877317 (patch) | |
tree | ca4964f3e851cd4b77879652aec225ea5daa1ca4 /doc/development | |
parent | 2458ea514066142e3ca8e5131e44925398902a77 (diff) | |
download | gitlab-ce-7a20b3758e651fe79032a5165db2208183877317.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development')
-rw-r--r-- | doc/development/testing_guide/frontend_testing.md | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/doc/development/testing_guide/frontend_testing.md b/doc/development/testing_guide/frontend_testing.md index d8f3a18577f..5e142d5c278 100644 --- a/doc/development/testing_guide/frontend_testing.md +++ b/doc/development/testing_guide/frontend_testing.md @@ -423,6 +423,40 @@ it('does something', () => { }); ``` +### Mocking the current location in Jest + +If your tests require `window.location.href` to take a particular value, use +the `setWindowLocation` helper: + +```javascript +import setWindowLocation from 'helpers/set_window_location'; + +it('passes', () => { + setWindowLocation('https://gitlab.test/foo?bar=true'); + + expect(window.location).toMatchObject({ + hostname: 'gitlab.test', + pathname: '/foo', + search: '?bar=true', + }); +}); +``` + +If your tests need to assert that certain `window.location` methods were +called, use the `useMockLocationHelper` helper: + +```javascript +import { useMockLocationHelper } from 'helpers/mock_window_location_helper'; + +useMockLocationHelper(); + +it('passes', () => { + window.location.reload(); + + expect(window.location.reload).toHaveBeenCalled(); +}); +``` + ### Waiting in tests Sometimes a test needs to wait for something to happen in the application before it continues. |