@@ -6,7 +6,6 @@ title: Examples
6
6
## Basic example
7
7
8
8
``` html
9
- <!-- src/TestComponent.vue -->
10
9
<template >
11
10
<div >
12
11
<p >Times clicked: {{ count }}</p >
@@ -16,11 +15,9 @@ title: Examples
16
15
17
16
<script >
18
17
export default {
19
- data () {
20
- return {
21
- count: 0 ,
22
- }
23
- },
18
+ data : () => ({
19
+ count: 0 ,
20
+ }),
24
21
25
22
methods: {
26
23
increment () {
@@ -32,16 +29,15 @@ title: Examples
32
29
```
33
30
34
31
``` js
35
- // src/TestComponent.spec.js
36
32
import { render , fireEvent , cleanup } from ' @testing-library/vue'
37
- import TestComponent from ' ./TestComponent .vue'
33
+ import Component from ' ./Component .vue'
38
34
39
35
// automatically unmount and cleanup DOM after the test is finished.
40
36
afterEach (cleanup)
41
37
42
- it (' increments value on click' , async () => {
38
+ test (' increments value on click' , async () => {
43
39
// The render method returns a collection of utilities to query your component.
44
- const { getByText } = render (TestComponent )
40
+ const { getByText } = render (Component )
45
41
46
42
// getByText returns the first matching node for the provided text, and
47
43
// throws an error if no elements match or if more than one match is found.
@@ -71,18 +67,16 @@ it('increments value on click', async () => {
71
67
72
68
<script >
73
69
export default {
74
- data () {
75
- return {
76
- user: ' Alice' ,
77
- }
78
- },
70
+ data : () => ({
71
+ user: ' Alice' ,
72
+ }),
79
73
}
80
74
</script >
81
75
```
82
76
83
77
``` js
84
78
import { render , fireEvent , cleanup } from ' @testing-library/vue'
85
- import Component from ' ./Component'
79
+ import Component from ' ./Component.vue '
86
80
87
81
afterEach (cleanup)
88
82
@@ -92,6 +86,7 @@ test('properly handles v-model', async () => {
92
86
// Asserts initial state.
93
87
getByText (' Hi, my name is Alice' )
94
88
89
+ // Get the input DOM node by querying the associated label.
95
90
const usernameInput = getByLabelText (/ username/ i )
96
91
97
92
// Updates the <input> value and triggers an `input` event.
0 commit comments