|
| 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 --> |
0 commit comments