summaryrefslogtreecommitdiff
path: root/doc/development/testing_guide/frontend_testing.md
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-13 18:09:00 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-13 18:09:00 +0000
commite4dffdfe364af6c72dcb6b4671cb39a24e8e100c (patch)
tree6428a1c3472b14396645dcb280b219dbc0420c66 /doc/development/testing_guide/frontend_testing.md
parent0ab47b994caa80c5587f33dc818626b66cfdafe2 (diff)
downloadgitlab-ce-e4dffdfe364af6c72dcb6b4671cb39a24e8e100c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/testing_guide/frontend_testing.md')
-rw-r--r--doc/development/testing_guide/frontend_testing.md19
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,