Skip to content

Commit cd3647d

Browse files
committed
update demo projects
1 parent 122bc4b commit cd3647d

File tree

6 files changed

+237
-27
lines changed

6 files changed

+237
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Welcome to the Vue Testing Handbook!
66

77
## What is this?
88

9-
This is a collection of short, focused examples on how to test Vue components. It uses [`vue-test-utils`](https://github.com/vuejs/vue-test-utils), the official library for testing Vue components, and [Jest](https://jestjs.io/), a modern testing framework. It covers the `vue-test-utils` API, as well as best practises and useful parts of the Jest API for testing Vue components. A working demo project with the examples is also included, which you can pull down and run yourself.
9+
This is a collection of short, focused examples on how to test Vue components. It uses [`vue-test-utils`](https://github.com/vuejs/vue-test-utils), the official library for testing Vue components, and [Jest](https://jestjs.io/), a modern testing framework. It covers the `vue-test-utils` API, as well as best practices and useful parts of the Jest API for testing Vue components. A working demo project with the examples is also included, which you can pull down and run yourself.
1010

1111
## Languages
1212

demo-app/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@
1111
"@vue/composition-api": "^0.3.2",
1212
"axios": "^0.19.0",
1313
"flush-promises": "^1.0.0",
14-
"vue": "^2.6.10",
14+
"vue": "^2.6.11",
1515
"vue-router": "^3.1.3"
1616
},
1717
"devDependencies": {
18+
"@testing-library/jest-dom": "^5.11.3",
1819
"@vue/cli-plugin-babel": "^4.0.4",
1920
"@vue/cli-plugin-unit-jest": "^4.0.4",
2021
"@vue/cli-service": "^4.0.4",
21-
"@vue/test-utils": "^1.0.0-beta.32",
22+
"@vue/test-utils": "^1.0.4",
2223
"babel-core": "7.0.0-bridge.0",
2324
"babel-jest": "^24.9.0",
24-
"vue-template-compiler": "^2.5.16",
25+
"vue-template-compiler": "^2.6.11",
2526
"vuex": "^3.1.1"
2627
},
2728
"browserslist": [

demo-app/tests/unit/App.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ describe("App", () => {
2323
router.push("/nested-route")
2424
await wrapper.vm.$nextTick()
2525

26-
expect(wrapper.find(NestedRoute).exists()).toBe(true)
26+
expect(wrapper.findComponent(NestedRoute).exists()).toBe(true)
2727
})
2828
})

demo-app/tests/unit/Parent.spec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mount } from "@vue/test-utils"
2+
import '@testing-library/jest-dom'
23
import Parent from "@/components/Parent.vue"
34
import ParentWithManyChildren from "@/components/ParentWithManyChildren.vue"
45
import Child from "@/components/Child.vue"
@@ -7,7 +8,7 @@ describe("Parent", () => {
78
it("does not render a span", () => {
89
const wrapper = mount(Parent)
910

10-
expect(wrapper.find("span").isVisible()).toBe(false)
11+
expect(wrapper.find("span").element).not.toBeVisible()
1112
})
1213

1314
it("does render a span", () => {
@@ -17,13 +18,13 @@ describe("Parent", () => {
1718
}
1819
})
1920

20-
expect(wrapper.find("span").isVisible()).toBe(true)
21+
expect(wrapper.find("span").element).toBeVisible()
2122
})
2223

2324
it("does not render a Child component", () => {
2425
const wrapper = mount(Parent)
2526

26-
expect(wrapper.find(Child).exists()).toBe(false)
27+
expect(wrapper.findComponent(Child).exists()).toBe(false)
2728
})
2829

2930
it("renders a Child component", () => {
@@ -33,14 +34,14 @@ describe("Parent", () => {
3334
}
3435
})
3536

36-
expect(wrapper.find({ name: "Child" }).exists()).toBe(true)
37+
expect(wrapper.findComponent({ name: "Child" }).exists()).toBe(true)
3738
})
3839
})
3940

4041
describe("ParentWithManyChildren", () => {
4142
it("renders many children", () => {
4243
const wrapper = mount(ParentWithManyChildren)
4344

44-
expect(wrapper.findAll(Child).length).toBe(3)
45+
expect(wrapper.findAllComponents(Child).length).toBe(3)
4546
})
4647
})

demo-app/tests/unit/ParentWithAPICallChild.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ describe('ParentWithAPICallChild.vue', () => {
1010
}
1111
})
1212

13-
expect(wrapper.find(ComponentWithAsyncCall).exists()).toBe(true)
13+
expect(wrapper.findComponent(ComponentWithAsyncCall).exists()).toBe(true)
1414
})
1515

1616
it('renders with shallowMount and does not initialize API call', () => {
1717
const wrapper = shallowMount(ParentWithAPICallChild)
1818

19-
expect(wrapper.find(ComponentWithAsyncCall).exists()).toBe(true)
19+
expect(wrapper.findComponent(ComponentWithAsyncCall).exists()).toBe(true)
2020
})
2121
})

0 commit comments

Comments
 (0)