diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 21:09:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-13 21:09:00 +0300 |
commit | e4dffdfe364af6c72dcb6b4671cb39a24e8e100c (patch) | |
tree | 6428a1c3472b14396645dcb280b219dbc0420c66 /doc/development/testing_guide | |
parent | 0ab47b994caa80c5587f33dc818626b66cfdafe2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/testing_guide')
-rw-r--r-- | doc/development/testing_guide/frontend_testing.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/doc/development/testing_guide/frontend_testing.md b/doc/development/testing_guide/frontend_testing.md index 9dc06a4b8b8..26357d4fdfd 100644 --- a/doc/development/testing_guide/frontend_testing.md +++ b/doc/development/testing_guide/frontend_testing.md @@ -202,6 +202,25 @@ For example, it's better to use the generated markup to trigger a button click a Following you'll find some general common practices you will find as part of our testsuite. Should you stumble over something not following this guide, ideally fix it right away. 🎉 +### How to query DOM elements + +When it comes to querying DOM elements in your tests, it is best to uniquely target the element, without adding additional attributes specifically for testing purposes. Sometimes this cannot be done feasibly. In these cases, adding test attributes to simplify the selectors might be the best option. + +Preferentially, in component testing with `@vue/test-utils`, you should query for child components using the component itself. Otherwise, try to use an existing attribute like `name` or a Vue `ref` (if using `@vue/test-utils`): + +```javascript +it('exists', () => { + wrapper.find(FooComponent); + wrapper.find('input[name=foo]'); + wrapper.find({ ref: 'foo'}); + wrapper.find('.js-foo'); +}); +``` + +It is not recommended that you add `.js-*` classes just for testing purposes. Only do this if there are no other feasible options available. + +Do not use a `.qa-*` class or `data-qa-selector` attribute for any tests other than QA end-to-end testing. + ### Naming unit tests When writing describe test blocks to test specific functions/methods, |