Skip to content

Commit a4694cf

Browse files
afontcualexkrolick
authored andcommitted
Add FAQ section to Vue docs (testing-library#136)
* Fix missing link * Add FAQ section for Vue
1 parent e418d0c commit a4694cf

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

docs/dom-testing-library/faq.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,13 @@ const thirdItem = getByTestId(container, `item-${items[2].id}`)
9393
```
9494

9595
</details>
96+
97+
<!--
98+
Links:
99+
-->
100+
101+
<!-- prettier-ignore-start -->
102+
103+
[guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106
104+
105+
<!-- prettier-ignore-end -->

docs/vue-testing-library/faq.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
id: faq
3+
title: FAQ
4+
---
5+
6+
See also the [main FAQ](dom-testing-library/faq.md) for questions not specific
7+
to Vue testing.
8+
9+
<details>
10+
<summary>**Is Vue Testing Library a replacement for the official @vue/test-utils?**</summary>
11+
12+
Short answer: yes, it is. If you use Vue Testing Library (VTL) there's no need
13+
to install [@vue/test-utils][vue-test-utils].
14+
15+
Longer answer: VTL is built on top of the official testing library. It is used
16+
to render Vue components (by calling [`mount`][mount]) and exposes some of its
17+
methods (while hiding others).
18+
19+
You can check the full list of available methods in the
20+
[API](vue-testing-library/api.md) section.
21+
22+
</details>
23+
24+
<details>
25+
<summary>**Do I need to install DOM Testing Library?**</summary>
26+
27+
Nope! VTL imports everything it needs from DOM Testing Library, and then
28+
re-exports it.
29+
30+
</details>
31+
32+
<details>
33+
<summary>**What queries does Vue Testing Library provide?**</summary>
34+
35+
All queries from DOM Testing Library. See
36+
[Queries](dom-testing-library/api-queries.md) for full list.
37+
38+
</details>
39+
40+
<details>
41+
<summary>**If I can't use shallow rendering, how do I mock out components in tests?**</summary>
42+
43+
In general, you should avoid mocking out components (see
44+
[the Guiding Principles section](guiding-principles.md)).
45+
46+
However if you need to, you can either use Jest's
47+
[mocking feature](https://facebook.github.io/jest/docs/en/manual-mocks.html) or
48+
the [`stubs`][stubs] key provided by @vue/test-utils.
49+
50+
```js
51+
import { render } from '@vue/test-utils'
52+
import Component from './Component'
53+
54+
test('Can stub components', () => {
55+
render(Component, {
56+
stubs: ['FontAwesomeIcon'],
57+
})
58+
})
59+
```
60+
61+
You can check out a [working example][stubs-example] in the GitHub repository of
62+
VTL.
63+
64+
</details>
65+
66+
<!--
67+
Links:
68+
-->
69+
70+
<!-- prettier-ignore-start -->
71+
72+
[vue-test-utils]: https://github.com/vuejs/vue-test-utils
73+
[mount]: https://vue-test-utils.vuejs.org/api/#mount
74+
[stubs]: https://vue-test-utils.vuejs.org/api/options.html#stubs
75+
[stubs-example]: https://github.com/testing-library/vue-testing-library/blob/master/tests/__tests__/stubs.js
76+
77+
<!-- prettier-ignore-end -->

website/sidebars.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"vue-testing-library/intro",
5858
"vue-testing-library/examples",
5959
"vue-testing-library/setup",
60-
"vue-testing-library/api"
60+
"vue-testing-library/api",
61+
"vue-testing-library/faq"
6162
]
6263
},
6364
"cypress-testing-library/intro",

0 commit comments

Comments
 (0)