Skip to content

Commit f8f87ef

Browse files
committed
Update to current API
1 parent c09c4c0 commit f8f87ef

31 files changed

+659
-62
lines changed

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Simple and completed Vue DOM testing utilities that encourage good testing practices.",
55
"main": "src/index.js",
66
"scripts": {
7-
"test": "jest --verbose"
7+
"test": "jest --verbose --watch"
88
},
99
"author": "Daniel Cook",
1010
"license": "MIT",
@@ -17,12 +17,14 @@
1717
"babel-plugin-transform-runtime": "^6.23.0",
1818
"babel-preset-env": "^1.6.1",
1919
"jest": "^22.4.2",
20+
"jest-in-case": "^1.0.2",
2021
"jest-serializer-vue": "^1.0.0",
2122
"vue": "^2.5.16",
2223
"vue-jest": "^2.2.1",
2324
"vue-router": "^3.0.1",
2425
"vue-template-compiler": "^2.5.16",
25-
"vuex": "^3.0.1"
26+
"vuex": "^3.0.1",
27+
"wait-for-expect": "^0.4.0"
2628
},
2729
"jest": {
2830
"moduleDirectories": [
@@ -33,6 +35,10 @@
3335
"js",
3436
"vue"
3537
],
38+
"testPathIgnorePatterns": [
39+
"/node_modules/",
40+
"<rootDir>/src/__tests__/components/"
41+
],
3642
"transform": {
3743
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
3844
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"

src/Simulate.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
export default {
2-
click(elem) {
3-
if (elem) {
4-
elem.click()
2+
click(elem) {
3+
if (elem) {
4+
if (elem.trigger) {
5+
elem.trigger('submit')
6+
}
7+
8+
if (elem.click) {
9+
elem.click()
10+
}
11+
}
12+
},
13+
submit(elem) {
14+
if (elem) {
15+
if (elem.trigger) {
16+
elem.trigger('submit')
17+
}
18+
19+
if (elem.submit) {
20+
elem.submit()
21+
}
522
}
623
}
724
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`get throws a useful error message 1`] = `"Unable to find a label with the text of: LucyRicardo"`;
4+
5+
exports[`get throws a useful error message 2`] = `"Unable to find an element with the placeholder text of: LucyRicardo"`;
6+
7+
exports[`get throws a useful error message 3`] = `"Unable to find an element with the text: LucyRicardo. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible."`;
8+
9+
exports[`get throws a useful error message 4`] = `"Unable to find an element by: [data-testid=\\"LucyRicardo\\"]"`;
10+
11+
exports[`get throws a useful error message 5`] = `"Unable to find an element with the alt text: LucyRicardo"`;
12+
13+
exports[`label with no form control 1`] = `"Found a label with the text of: alone, however no form control was found associated to that label. Make sure you're using the \\"for\\" attribute or \\"aria-labelledby\\" attribute correctly."`;
14+
15+
exports[`totally empty label 1`] = `"Found a label with the text of: , however no form control was found associated to that label. Make sure you're using the \\"for\\" attribute or \\"aria-labelledby\\" attribute correctly."`;

src/__tests__/components/EndToEnd.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<div v-if="loading">
3+
Loading...
4+
</div>
5+
<div v-else data-testid="message">
6+
Loaded this message: {{ data.returnedMessage }}
7+
</div>
8+
</template>
9+
10+
<script>
11+
const fetchAMessage = () =>
12+
new Promise(resolve => {
13+
// we are using random timeout here to simulate a real-time example
14+
// of an async operation calling a callback at a non-deterministic time
15+
const randomTimeout = Math.floor(Math.random() * 100)
16+
setTimeout(() => {
17+
resolve({returnedMessage: 'Hello World'})
18+
}, randomTimeout)
19+
})
20+
21+
export default {
22+
data () {
23+
return {
24+
loading: true,
25+
data: {
26+
returnedMessage: null
27+
}
28+
}
29+
},
30+
async mounted () {
31+
const data = await fetchAMessage()
32+
this.loading = false
33+
this.data = data
34+
}
35+
}
36+
</script>

src/__tests__/components/Login.vue

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<template>
2+
<div>
3+
<form @submit.prevent="submit">
4+
<label for="username-input">Username</label>
5+
<input v-model="username" id="username-input" placeholder="Username..." name="username" />
6+
<label id="password-label">Password</label>
7+
<input
8+
v-model="password"
9+
placeholder="Password..."
10+
type="password"
11+
name="password"
12+
aria-labelledby="password-label"
13+
/>
14+
<button type="submit">Submit</button>
15+
</form>
16+
</div>
17+
</template>
18+
19+
<script>
20+
export default {
21+
props: {
22+
onSubmit: {
23+
type: Function,
24+
required: true
25+
}
26+
},
27+
data () {
28+
return {
29+
username: '',
30+
password: ''
31+
}
32+
},
33+
methods: {
34+
submit () {
35+
this.onSubmit({
36+
username: this.username,
37+
password: this.password
38+
})
39+
}
40+
}
41+
}
42+
</script>
43+

src/__tests__/components/Router/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</template>
1313

1414
<script>
15-
import LocationDisplay from './LocationDisplay.vue'
15+
import LocationDisplay from './LocationDisplay'
1616
1717
export default {
1818
components: {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<template functional>
1+
<template>
22
<div>You are home</div>
33
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<a href="/about" id="anchor">About</a>
3+
</template>

src/__tests__/components/VuexTest.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@
22
<div>
33
<h2>Counter</h2>
44
<div>
5-
<button @click="decrement" data-testid="decrementer">
6-
-
7-
</button>
5+
<button @click="decrement" data-testid="decrementer">-</button>
86
<span data-testid="count-value">{{ count }}</span>
9-
<button @click="increment" data-testid="incrementer">
10-
+
11-
</button>
7+
<button @click="increment" data-testid="incrementer">+</button>
128
</div>
139
</div>
1410
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<span data-testid="count-value">2</span>
3+
</template>

0 commit comments

Comments
 (0)