Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e07eb02

Browse files
committedApr 6, 2018
Move querying logic to dom-testing-library
1 parent 08f6d6f commit e07eb02

File tree

14 files changed

+23
-493
lines changed

14 files changed

+23
-493
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ It's primary guiding principle is:
2222

2323
The more your tests resemble the way your software is used, the more confidence they can give you.
2424

25-
The intention is to closely track react-test-utils and its capabilities. As such significant parts of its code are repeated here verbatim. All credit for this must go to Kent C Dodds and the other contributors to that project.
25+
The intention is to closely track react-test-utils and its capabilities. To this end it uses the marvellous `dom-testing-utils` library for querying the DOM.
26+
2627

2728
## Installation
2829

‎package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"author": "Daniel Cook",
2626
"license": "MIT",
2727
"dependencies": {
28+
"dom-testing-library": "^1.0.0",
2829
"@vue/test-utils": "^1.0.0-beta.12",
2930
"vue": "^2.5.16",
3031
"vue-router": "^3.0.1",
3132
"vue-template-compiler": "^2.5.16",
32-
"vuex": "^3.0.1",
33-
"wait-for-expect": "^0.4.0"
33+
"vuex": "^3.0.1"
3434
},
3535
"devDependencies": {
3636
"axios": "^0.18.0",

‎src/extend-expect.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎src/index.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { createLocalVue, mount, Wrapper } from '@vue/test-utils'
22
import Vuex from 'vuex'
33
import VueRouter from 'vue-router'
4-
import waitForExpect from 'wait-for-expect'
54
import Simulate from './Simulate'
6-
import * as queries from './queries'
5+
import { wait, queries } from 'dom-testing-library'
76

87
function render(TestComponent, { props = null, store = null, routes = null } = {}, configurationCb) {
98
const localVue = createLocalVue()
@@ -34,7 +33,7 @@ function render(TestComponent, { props = null, store = null, routes = null } = {
3433

3534
const wrapperHelpers = Object.entries(queries).reduce(
3635
(helpers, [key, fn]) => {
37-
helpers[key] = fn.bind(null, wrapper)
36+
helpers[key] = fn.bind(null, wrapper.element)
3837
return helpers
3938
},
4039
{},
@@ -50,8 +49,4 @@ function render(TestComponent, { props = null, store = null, routes = null } = {
5049
}
5150
}
5251

53-
function wait(callback = () => {}, {timeout = 4500, interval = 50} = {}) {
54-
return waitForExpect(callback, timeout, interval)
55-
}
56-
5752
export { render, wait, Simulate }

‎src/jest-extensions.js

Lines changed: 0 additions & 137 deletions
This file was deleted.

‎src/queries.js

Lines changed: 0 additions & 155 deletions
This file was deleted.

‎src/utils.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎tests/__tests__/__snapshots__/element-queries.js.snap

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎tests/__tests__/components/EndToEnd.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
2-
<div v-if="loading">
3-
Loading...
4-
</div>
5-
<div v-else data-testid="message">
6-
Loaded this message: {{ data.returnedMessage }}
2+
<div>
3+
<div v-if="loading">Loading...</div>
4+
<div v-else data-testid="message">
5+
Loaded this message: {{ data.returnedMessage }}
6+
</div>
77
</div>
88
</template>
99

‎tests/__tests__/element-queries.js

Lines changed: 0 additions & 130 deletions
This file was deleted.

‎tests/__tests__/end-to-end.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { render, wait } from '../../src'
22
import EndToEnd from './components/EndToEnd'
33

44
test('it waits for the data to be loaded', async () => {
5-
const {queryByText, queryByTestId} = render(EndToEnd)
5+
const { html, queryByText, queryByTestId } = render(EndToEnd)
66

77
expect(queryByText('Loading...')).toBeTruthy()
88

‎tests/__tests__/text-matchers.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎tests/__tests__/validate-plugin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Vue from 'vue'
22
import VeeValidate from 'vee-validate'
33

44
import { render, Simulate, wait } from '../../src'
5-
import '../../src/extend-expect'
65
import Validate from './components/Validate'
76

87
test('can validate using plugin', async () => {
@@ -15,5 +14,5 @@ test('can validate using plugin', async () => {
1514

1615
await wait()
1716

18-
expect(queryByTestId('username-errors')).toBeInTheDOM()
17+
expect(queryByTestId('username-errors').textContent).toBe('The username field is required.')
1918
})

0 commit comments

Comments
 (0)
Please sign in to comment.