1
1
<div align =" center " >
2
2
<h1 >Vue Testing Library</h1 >
3
3
4
- <p >Lightweight adapter allowing <a href =" https://github.com/testing-library/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 >
4
+ <a href =" https://www.joypixels.com/emoji/1F98E " >
5
+ <img
6
+ height="80"
7
+ width="80"
8
+ alt="lizard"
9
+ src="https://raw.githubusercontent.com/testing-library/vue-testing-library/master/lizard.png "
10
+ />
11
+ </a >
12
+
13
+ <p >Simple and complete Vue.js testing utilities that encourage good testing practices.</p >
14
+
15
+ <p >Vue Testing Library is a lightweight adapter built on top of <a href =" https://github.com/testing-library/dom-testing-library/ " >DOM Testing Library</a > and <a href =" https://github.com/vuejs/vue-test-utils " >@vue/test-utils</a >.</p >
5
16
6
17
<br />
7
18
8
- [ ** Read The Docs** ] ( https://testing-library.com/vue ) |
9
- [ Edit the docs] ( https://github.com/testing-library/testing-library-docs )
19
+ [ ** Read the Docs** ] [ docs ] | [ Edit the docs] [ docs-edit ]
10
20
11
21
<br />
12
22
13
23
</div >
14
24
15
25
<hr />
16
26
17
- [ ![ Build Status] ( https://travis-ci.org/testing-library/vue-testing-library.svg?branch=master )] ( https://travis-ci.org/testing-library/vue-testing-library )   ;  ;
18
- [ ![ Coverage Status] ( https://img.shields.io/codecov/c/github/testing-library/vue-testing-library.svg )] ( https://codecov.io/github/testing-library/vue-testing-library )   ;  ;
19
- [ ![ GitHub version] ( https://badge.fury.io/gh/testing-library%2Fvue-testing-library.svg )] ( https://badge.fury.io/gh/testing-library%2Fvue-testing-library )
27
+ <!-- prettier-ignore-start -->
28
+ [ ![ Build Status] [ build-badge ]] [ build ]
29
+ [ ![ Coverage Status] [ coverage-badge ]] [ coverage ]
30
+ [ ![ GitHub version] [ github-badge ]] [ github ]
31
+ [ ![ npm version] [ npm-badge ]] [ npm ]
20
32
21
- [ ![ npm version] ( https://badge.fury.io/js/%40testing-library%2Fvue.svg )] ( https://badge.fury.io/js/%40testing-library%2Fvue )   ;  ;
22
- [ ![ license] ( https://img.shields.io/github/license/testing-library/vue-testing-library.svg )] ( https://img.shields.io/github/license/testing-library/vue-testing-library )
33
+ [ ![ MIT License] [ license-badge ]] [ license ]
34
+ [ ![ Join the community on Spectrum] [ spectrum-badge ]] [ spectrum ]
35
+ <!-- prettier-ignore-end -->
23
36
24
37
<h2 >Table of Contents</h2 >
25
38
26
39
- [ Installation] ( #installation )
27
- - [ Examples] ( #examples )
40
+ - [ A simple example] ( #a-simple-example )
41
+ - [ More examples] ( #more-examples )
28
42
- [ Docs] ( #docs )
29
43
- [ License] ( #license )
30
44
- [ Contributors] ( #contributors )
31
45
32
46
## Installation
33
47
34
- This module is distributed via npm which is bundled with node and
35
- should be installed as one of your project's ` devDependencies ` :
48
+ This module is distributed via npm and should be installed as one of your
49
+ project's ` devDependencies ` :
36
50
37
51
```
38
52
npm install --save-dev @testing-library/vue
39
53
```
40
54
55
+ This library has ` peerDependencies ` listings for ` Vue ` and
56
+ ` vue-template-compiler ` .
57
+
41
58
You may also be interested in installing ` jest-dom ` so you can use
42
59
[ the custom Jest matchers] ( https://github.com/gnapse/jest-dom#readme ) .
43
60
44
- ## Examples
61
+ ## A simple example
45
62
46
63
``` html
47
64
<!-- TestComponent.vue -->
@@ -53,74 +70,98 @@ You may also be interested in installing `jest-dom` so you can use
53
70
</template >
54
71
55
72
<script >
56
- export default {
57
- data : () => ({
58
- count: 0
59
- }),
60
- methods: {
61
- increment () {
62
- this .count ++
73
+ export default {
74
+ data : () => ({
75
+ count: 0
76
+ }),
77
+ methods: {
78
+ increment () {
79
+ this .count ++
80
+ }
63
81
}
64
82
}
65
- }
66
83
</script >
67
84
```
68
85
69
86
``` js
70
87
// TestComponent.spec.js
71
- import { render , fireEvent , cleanup } from ' @testing-library/vue'
88
+ import { render , fireEvent } from ' @testing-library/vue'
72
89
import TestComponent from ' ./TestComponent.vue'
73
90
74
- // automatically unmount and cleanup DOM after the test is finished.
75
- afterEach (cleanup)
76
-
77
- it (' increments value on click' , async () => {
91
+ test (' increments value on click' , async () => {
78
92
// The render method returns a collection of utilities to query your component.
79
93
const { getByText } = render (TestComponent)
80
94
81
95
// getByText returns the first matching node for the provided text, and
82
96
// throws an error if no elements match or if more than one match is found.
83
97
getByText (' Times clicked: 0' )
84
98
99
+ // `button` is the actual DOM element.
85
100
const button = getByText (' increment' )
86
101
87
- // Dispatch a native click event to our button element .
102
+ // Dispatch a native click event.
88
103
await fireEvent .click (button)
89
104
await fireEvent .click (button)
90
105
91
106
getByText (' Times clicked: 2' )
92
107
})
93
108
```
94
109
95
- You'll find examples of testing with different libraries in
96
- [ the test directory] ( https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__ ) .
110
+ ### More examples
111
+
112
+ You'll find examples of testing with different situations and popular libraries
113
+ in [ the test directory] [ test-directory ] .
97
114
98
115
Some included are:
99
116
100
- * [ ` vuex ` ] ( https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/vuex.js )
101
- * [ ` vue-router ` ] ( https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/vue-router.js )
102
- * [ ` vee-validate ` ] ( https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/validate-plugin.js )
117
+ - [ ` vuex ` ] [ vuex-example ]
118
+ - [ ` vue-router ` ] [ vue-router-example ]
119
+ - [ ` vee-validate ` ] [ vee-validate-example ]
120
+ - [ ` vue-i18n ` ] [ vue-i18n-example ]
103
121
104
- Feel free to contribute with more!
122
+ Feel free to contribute with more examples !
105
123
106
124
## Docs
107
125
108
- [ ** Read The Docs** ] ( https://testing-library.com/vue ) |
109
- [ Edit the docs] ( https://github.com/testing-library/testing-library-docs )
126
+ [ ** Read the Docs** ] [ docs ] | [ Edit the docs] [ docs-edit ]
110
127
111
128
## License
112
129
113
- MIT
130
+ [ MIT] [ license ]
114
131
115
132
## Contributors
116
133
117
- [ ![ dfcook] ( https://avatars0.githubusercontent.com/u/10348212?v=3&s=200 )] ( https://github.com/dfcook )
118
- [ ![ afontcu] ( https://avatars3.githubusercontent.com/u/9197791?s=200&v=3 )] ( https://github.com/afontcu )
119
- [ ![ eunjae-lee] ( https://avatars0.githubusercontent.com/u/499898?v=3&s=200 )] ( https://github.com/eunjae-lee )
120
- [ ![ tim-maguire] ( https://avatars0.githubusercontent.com/u/29452317?v=3&s=200 )] ( https://github.com/tim-maguire )
121
- [ ![ samdelacruz] ( https://avatars0.githubusercontent.com/u/2040007?v=3&s=200 )] ( https://github.com/samdelacruz )
122
- [ ![ ankitsinghaniyaz] ( https://avatars0.githubusercontent.com/u/11331989?v=3&s=200 )] ( https://github.com/ankitsinghaniyaz )
123
- [ ![ lindgr3n] ( https://avatars0.githubusercontent.com/u/24882614?v=3&s=200 )] ( https://github.com/lindgr3n )
124
- [ ![ kentcdodds] ( https://avatars0.githubusercontent.com/u/1500684?v=3&s=200 )] ( https://github.com/kentcdodds )
125
- [ ![ brennj] ( https://avatars2.githubusercontent.com/u/29227924?v=3&s=200 )] ( https://github.com/brennj )
126
- [ ![ makeupsomething] ( https://avatars2.githubusercontent.com/u/7676733?v=3&s=200 )] ( https://github.com/makeupsomething )
134
+ [ ![ dfcook] ( https://avatars0.githubusercontent.com/u/10348212?v=3&s=170 )] ( https://github.com/dfcook )
135
+ [ ![ afontcu] ( https://avatars3.githubusercontent.com/u/9197791?s=170&v=3 )] ( https://github.com/afontcu )
136
+ [ ![ eunjae-lee] ( https://avatars0.githubusercontent.com/u/499898?v=3&s=170 )] ( https://github.com/eunjae-lee )
137
+ [ ![ tim-maguire] ( https://avatars0.githubusercontent.com/u/29452317?v=3&s=170 )] ( https://github.com/tim-maguire )
138
+ [ ![ samdelacruz] ( https://avatars0.githubusercontent.com/u/2040007?v=3&s=170 )] ( https://github.com/samdelacruz )
139
+ [ ![ ankitsinghaniyaz] ( https://avatars0.githubusercontent.com/u/11331989?v=3&s=170 )] ( https://github.com/ankitsinghaniyaz )
140
+ [ ![ lindgr3n] ( https://avatars0.githubusercontent.com/u/24882614?v=3&s=170 )] ( https://github.com/lindgr3n )
141
+ [ ![ kentcdodds] ( https://avatars0.githubusercontent.com/u/1500684?v=3&s=170 )] ( https://github.com/kentcdodds )
142
+ [ ![ brennj] ( https://avatars2.githubusercontent.com/u/29227924?v=3&s=170 )] ( https://github.com/brennj )
143
+ [ ![ makeupsomething] ( https://avatars2.githubusercontent.com/u/7676733?v=3&s=170 )] ( https://github.com/makeupsomething )
144
+
145
+ <!-- prettier-ignore-start -->
146
+ [ build-badge ] : https://travis-ci.org/testing-library/vue-testing-library.svg?branch=master
147
+ [ build ] : https://travis-ci.org/testing-library/vue-testing-library
148
+ [ spectrum-badge ] : https://withspectrum.github.io/badge/badge.svg
149
+ [ spectrum ] : https://spectrum.chat/testing-library
150
+ [ coverage-badge ] : https://img.shields.io/codecov/c/github/testing-library/vue-testing-library.svg
151
+ [ coverage ] : https://codecov.io/github/testing-library/vue-testing-library
152
+ [ github-badge ] : https://badge.fury.io/gh/testing-library%2Fvue-testing-library.svg
153
+ [ github ] : https://badge.fury.io/gh/testing-library%2Fvue-testing-library
154
+ [ npm-badge ] : https://badge.fury.io/js/%40testing-library%2Fvue.svg
155
+ [ npm ] : https://badge.fury.io/js/%40testing-library%2Fvue
156
+ [ license-badge ] : https://img.shields.io/github/license/testing-library/vue-testing-library.svg
157
+ [ license ] : https://github.com/testing-library/vue-testing-library/blob/master/LICENSE
158
+
159
+ [ docs ] : https://testing-library.com/vue
160
+ [ docs-edit ] : https://github.com/testing-library/testing-library-docs
161
+
162
+ [ test-directory ] : https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__
163
+ [ vuex-example ] : https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/vuex.js
164
+ [ vue-router-example ] : https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/vue-router.js
165
+ [ vee-validate-example ] : https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/validate-plugin.js
166
+ [ vue-i18n-example ] : https://github.com/testing-library/vue-testing-library/blob/master/tests/__tests__/vueI18n.js
167
+ <!-- prettier-ignore-end -->
0 commit comments