Skip to content

Commit 9dfc312

Browse files
committed
Update to latest dom-testing-library
1 parent 6ecf1b7 commit 9dfc312

File tree

17 files changed

+3723
-5029
lines changed

17 files changed

+3723
-5029
lines changed

.babelrc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"presets": [
3-
["env", {
4-
"modules": false,
3+
["@babel/env", {
4+
"modules": "commonjs",
55
"targets": {
6+
"node": "current",
67
"browsers": [
78
"> 1%",
89
"last 2 versions",
@@ -12,12 +13,7 @@
1213
}]
1314
],
1415
"plugins": [
15-
"transform-object-rest-spread",
16-
"transform-runtime"
17-
],
18-
"env": {
19-
"test": {
20-
"presets": ["env"]
21-
}
22-
}
16+
"@babel/plugin-proposal-object-rest-spread",
17+
"@babel/plugin-transform-runtime"
18+
]
2319
}

package-lock.json

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

package.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,35 @@
2727
"author": "Daniel Cook",
2828
"license": "MIT",
2929
"dependencies": {
30-
"@vue/test-utils": "^1.0.0-beta.16",
31-
"dom-testing-library": "^2.3.2",
32-
"vue": "^2.5.16",
33-
"vue-template-compiler": "^2.5.16"
30+
"@vue/test-utils": "^1.0.0-beta.25",
31+
"babel-core": "^7.0.0-bridge.0",
32+
"dom-testing-library": "^3.12.4",
33+
"vue": "^2.5.17",
34+
"vue-template-compiler": "^2.5.17"
3435
},
3536
"devDependencies": {
37+
"@babel/cli": "^7.1.5",
38+
"@babel/core": "^7.1.6",
39+
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
40+
"@babel/plugin-transform-runtime": "^7.1.0",
41+
"@babel/preset-env": "^7.1.6",
3642
"axios": "^0.18.0",
37-
"babel-cli": "^6.26.0",
38-
"babel-core": "^6.26.3",
39-
"babel-eslint": "^8.2.3",
40-
"babel-jest": "^23.0.1",
41-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
42-
"babel-plugin-transform-runtime": "^6.23.0",
43-
"babel-preset-env": "^1.7.0",
44-
"babel-preset-es2015": "^6.24.1",
45-
"coveralls": "^3.0.1",
46-
"eslint": "^4.19.1",
47-
"eslint-config-standard": "^12.0.0-alpha.0",
48-
"eslint-plugin-import": "^2.12.0",
49-
"eslint-plugin-node": "^6.0.1",
50-
"eslint-plugin-promise": "^3.8.0",
51-
"eslint-plugin-standard": "^3.1.0",
52-
"eslint-plugin-vue": "^4.5.0",
53-
"jest": "^23.1.0",
43+
"babel-eslint": "^10.0.1",
44+
"babel-jest": "^23.6.0",
45+
"coveralls": "^3.0.2",
46+
"eslint": "^5.9.0",
47+
"eslint-config-standard": "^12.0.0",
48+
"eslint-plugin-import": "^2.14.0",
49+
"eslint-plugin-node": "^8.0.0",
50+
"eslint-plugin-promise": "^4.0.1",
51+
"eslint-plugin-standard": "^4.0.0",
52+
"eslint-plugin-vue": "^4.7.1",
53+
"jest": "^23.6.0",
5454
"jest-in-case": "^1.0.2",
55-
"jest-serializer-vue": "^2.0.0",
56-
"vee-validate": "^2.1.0-beta.1",
57-
"vue-jest": "^2.6.0",
58-
"vue-router": "^3.0.1",
55+
"jest-serializer-vue": "^2.0.2",
56+
"vee-validate": "^2.1.3",
57+
"vue-jest": "^3.0.0",
58+
"vue-router": "^3.0.2",
5959
"vuex": "^3.0.1"
6060
},
6161
"jest": {

src/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createLocalVue, mount } from '@vue/test-utils'
22
import Simulate from './Simulate'
3-
import { getQueriesForElement, fireEvent, wait, waitForElement } from 'dom-testing-library'
3+
import { getQueriesForElement, prettyDOM, wait } from 'dom-testing-library'
4+
5+
const mountedWrappers = new Set()
46

57
function render (TestComponent, { props = null, store = null, routes = null } = {}, configurationCb) {
68
const localVue = createLocalVue()
@@ -28,17 +30,35 @@ function render (TestComponent, { props = null, store = null, routes = null } =
2830
router,
2931
store: vuexStore,
3032
propsData: { ...props },
31-
attachToDocument: true
33+
attachToDocument: true,
34+
sync: false
3235
})
3336

3437
return {
38+
debug: () => console.log(prettyDOM(wrapper.element)),
3539
unmount: () => wrapper.destroy(),
3640
isUnmounted: () => wrapper.vm._isDestroyed,
3741
html: () => wrapper.html(),
38-
updateProps: _ => wrapper.setProps(_),
42+
updateProps: _ => {
43+
wrapper.setProps(_)
44+
return wait()
45+
},
3946
updateState: _ => wrapper.setData(_),
4047
...getQueriesForElement(wrapper.element)
4148
}
4249
}
4350

44-
export { render, Simulate, fireEvent, wait, waitForElement }
51+
function cleanup () {
52+
mountedWrappers.forEach(cleanupAtWrapper)
53+
}
54+
55+
function cleanupAtWrapper (wrapper) {
56+
if (wrapper.parentNode === document.body) {
57+
document.body.removeChild(wrapper)
58+
}
59+
wrapper.destroy()
60+
mountedWrappers.delete(wrapper)
61+
}
62+
63+
export * from 'dom-testing-library'
64+
export { cleanup, render, Simulate }

tests/__mocks__/axios.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
get: jest.fn(() => Promise.resolve({data: {}}))
2+
get: jest.fn(() => Promise.resolve({ data: {} }))
33
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Fetch makes an API call and displays the greeting when load-greeting is clicked 1`] = `
4-
<div>
5-
<button data-testid="load-greeting">
4+
<div><button data-testid="load-greeting">
65
Fetch
7-
</button> <span data-testid="greeting-text">hello there</span> {{ data ? : null}
6+
</button> <span data-testid="greeting-text">hello there</span>
7+
{{ data ? : null}
88
</div>
99
`;

tests/__tests__/components/EndToEnd.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const fetchAMessage = () =>
1616
// of an async operation calling a callback at a non-deterministic time
1717
const randomTimeout = Math.floor(Math.random() * 100)
1818
setTimeout(() => {
19-
resolve({returnedMessage: 'Hello World'})
19+
resolve({ returnedMessage: 'Hello World' })
2020
}, randomTimeout)
2121
})
2222
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div>Hello World!</div>
3+
</template>

tests/__tests__/components/Login.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<label for="username-input">Username</label>
55
<input
66
id="username-input"
7-
data-testid="username-input"
87
v-model="username"
8+
data-testid="username-input"
99
placeholder="Username..."
1010
name="username" >
1111
<label id="password-label">Password</label>

tests/__tests__/components/Router/LocationDisplay.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
<script>
66
export default {
7-
7+
88
}
99
</script>
10-

0 commit comments

Comments
 (0)