|
1 | 1 | <div align="center">
|
2 | 2 | <h1>vue-testing-library</h1>
|
3 | 3 |
|
4 |
| -<p>Port of the ultra-low surface area testing library <a href="https://github.com/kentcdodds/react-testing-library/">react-testing-library</a> to <a href="https://github.com/vuejs/vue">Vue.js</a> using <a href="https://github.com/vuejs/vue-test-utils">@vue/test-utils</a></p> |
| 4 | +<p>Lightweight adapter allowing <a href="https://github.com/kentcdodds/dom-testing-library/">dom-testing-library</a> to be used to test <a href="https://github.com/vuejs/vue">Vue.js</a> components built on top of <a href="https://github.com/vuejs/vue-test-utils">@vue/test-utils</a></p> |
5 | 5 |
|
6 | 6 | </div>
|
7 | 7 |
|
|
16 | 16 |
|
17 | 17 | ## This library
|
18 | 18 |
|
19 |
| -The `vue-testing-library` is a very light-weight solution for testing Vue |
20 |
| -components. It provides light utility functions on top of `@vue/test-utils`, in a way that encourages better testing practices. |
21 |
| -It's primary guiding principle is: |
22 |
| - |
23 |
| -The more your tests resemble the way your software is used, the more confidence they can give you. |
24 |
| - |
25 |
| -The intention is to closely track react-test-utils and its capabilities. To this end it uses the marvellous `dom-testing-utils` library for querying the DOM. |
| 19 | +The `vue-testing-library` is a an adapter that enables Vue testing using the framework-agnostic DOM testing library `dom-testing-library` |
26 | 20 |
|
| 21 | +* [Installation](#installation) |
| 22 | +* [Usage](#usage) |
| 23 | + * [`render`](#render) |
| 24 | + * [`Simulate`](#simulate) |
| 25 | + * [`wait`](#wait) |
| 26 | +* [Examples](#examples) |
| 27 | +* [LICENSE](#license) |
27 | 28 |
|
28 | 29 | ## Installation
|
29 | 30 |
|
@@ -108,6 +109,43 @@ test('should render HelloWorld', () => {
|
108 | 109 |
|
109 | 110 | ```
|
110 | 111 |
|
| 112 | +### render |
| 113 | + |
| 114 | +The `render` function takes up to 3 parameters and returns an object with some helper methods |
| 115 | + |
| 116 | +1. Component - the Vue component to be tested. |
| 117 | +2. RenderOptions - an object containing additional information to be passed to @vue/test-utils mount. This can be: |
| 118 | +* props - The component props to be passed to TestComponent |
| 119 | +* store - The object definition of a Vuex store, if present `render` will configure a Vuex store and pass to mount. |
| 120 | +* routes - A set of routes, if present render will configure VueRouter and pass to mount. |
| 121 | +3. configurationCb - A callback to be called passing the Vue instance when created. This allows 3rd party plugins to be installed prior to mount. |
| 122 | + |
| 123 | +### Simulate |
| 124 | + |
| 125 | +Lightweight wrapper around DOM element methods |
| 126 | + |
| 127 | +### wait |
| 128 | + |
| 129 | +When in need to wait for non-deterministic periods of time you can use `wait`, |
| 130 | +to wait for your expectations to pass. The `wait` function is a small wrapper |
| 131 | +around the |
| 132 | +[`wait-for-expect`](https://github.com/TheBrainFamily/wait-for-expect) module. |
| 133 | + |
| 134 | +Waiting can be very important in Vue components, @vue/test-utils has succeeded in making the majority of updates happen |
| 135 | +synchronously however there are occasions when wait will allow the DOM to update. For example, see [`here`](https://github.com/dfcook/vue-testing-library/tree/master/tests/__tests__/validate-plugin.js) |
| 136 | + |
| 137 | +## Examples |
| 138 | + |
| 139 | +You'll find examples of testing with different libraries in |
| 140 | +[the test directory](https://github.com/dfcook/vue-testing-library/tree/master/tests/__tests__). |
| 141 | +Some included are: |
| 142 | + |
| 143 | +* [`vuex`](https://github.com/dfcook/vue-testing-library/tree/master/tests/__tests__/vuex.js) |
| 144 | +* [`vue-router`](https://github.com/dfcook/vue-testing-library/tree/master/__tests__/vue-router.js) |
| 145 | +* [`vee-validate`](https://github.com/dfcook/vue-testing-library/tree/master/tests/__tests__/validate-plugin.js) |
| 146 | + |
| 147 | +Feel free to contribute more! |
| 148 | + |
111 | 149 | ## LICENSE
|
112 | 150 |
|
113 | 151 | MIT
|
0 commit comments