Skip to content

Commit aeda1a9

Browse files
committed
Merge branch 'master' of github.com:testing-library/vue-testing-library
2 parents f5c9eca + e615376 commit aeda1a9

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div align="center">
22
<h1>vue-testing-library</h1>
33

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>
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>
55

66
</div>
77

@@ -16,7 +16,7 @@
1616

1717
## This library
1818

19-
The `vue-testing-library` is a an adapter that enables Vue testing using the framework-agnostic DOM testing library `dom-testing-library`
19+
The `vue-testing-library` is an adapter that enables Vue testing using the framework-agnostic DOM testing library `dom-testing-library`
2020

2121
* [Installation](#installation)
2222
* [Usage](#usage)
@@ -112,18 +112,18 @@ test('should render HelloWorld', () => {
112112

113113
### render
114114

115-
The `render` function takes up to 3 parameters and returns an object with some helper methods
115+
The `render` function takes up to 3 parameters and returns an object with some helper methods.
116116

117117
1. Component - the Vue component to be tested.
118118
2. RenderOptions - an object containing additional information to be passed to @vue/test-utils mount. This can be:
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.
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.
121121
All additional render options are passed to the vue-test-utils mount function in its options.
122122
3. configurationCb - A callback to be called passing the Vue instance when created, plus the store and router if specified. This allows 3rd party plugins to be installed prior to mount.
123123

124124
### fireEvent
125125

126-
Lightweight wrapper around DOM element events and methods. Will call wait, so can be awaited to allow effects to propagate.
126+
Lightweight wrapper around DOM element events and methods. Will call `wait`, so can be awaited to allow effects to propagate.
127127

128128
### wait
129129

@@ -133,7 +133,7 @@ around the
133133
[`wait-for-expect`](https://github.com/TheBrainFamily/wait-for-expect) module.
134134

135135
Waiting can be very important in Vue components, @vue/test-utils has succeeded in making the majority of updates happen
136-
synchronously however there are occasions when wait will allow the DOM to update. For example, see [`here`](https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/validate-plugin.js)
136+
synchronously however there are occasions when `wait` will allow the DOM to update. For example, see [`here`](https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/end-to-end.js)
137137

138138
## Examples
139139

@@ -145,7 +145,7 @@ Some included are:
145145
* [`vue-router`](https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/vue-router.js)
146146
* [`vee-validate`](https://github.com/testing-library/vue-testing-library/tree/master/tests/__tests__/validate-plugin.js)
147147

148-
Feel free to contribute more!
148+
Feel free to contribute with more!
149149

150150
## LICENSE
151151

tests/__tests__/components/Button.vue

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<button
33
:class="typeClass"
4-
@click="clicked"
4+
@click="handleClick"
55
>{{ text }}</button>
66
</template>
77

@@ -12,10 +12,6 @@ export default {
1212
type: String,
1313
default: ''
1414
},
15-
clicked: {
16-
type: Function,
17-
default: () => true
18-
},
1915
type: {
2016
validator: (value) => ['primary', 'secondary'].includes(value),
2117
default: 'primary'
@@ -28,6 +24,11 @@ export default {
2824
}
2925
return 'button'
3026
}
27+
},
28+
methods: {
29+
handleClick (e) {
30+
this.$emit('click')
31+
}
3132
}
3233
}
3334
</script>

tests/__tests__/router/programmatic-routing/components/Home.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<template>
22
<div>
33
<div>You are home</div>
4-
<button data-testid="go-to-about" @click="goToAbout">About</button>
4+
<button
5+
data-testid="go-to-about"
6+
@click="goToAbout">About</button>
57
</div>
68
</template>
79

@@ -14,4 +16,3 @@ export default {
1416
}
1517
}
1618
</script>
17-

tests/__tests__/simple-button.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ afterEach(cleanup)
66
test('renders button with text', () => {
77
const buttonText = "Click me; I'm sick"
88
const { getByText } = render(SimpleButton, {
9-
props: { text: buttonText, clicked: () => true }
9+
props: { text: buttonText }
1010
})
1111

1212
getByText(buttonText)
1313
})
1414

15-
test('clicked prop is called when button is clicked', () => {
16-
const clicked = jest.fn()
15+
test('click event is emitted when button is clicked', () => {
1716
const text = 'Click me'
18-
const { getByText } = render(SimpleButton, {
19-
props: { text, clicked }
17+
const { getByText, emitted } = render(SimpleButton, {
18+
props: { text }
2019
})
2120
fireEvent.click(getByText(text))
22-
expect(clicked).toBeCalled()
21+
expect(emitted().click).toHaveLength(1)
2322
})

0 commit comments

Comments
 (0)