Skip to content

Commit 356d624

Browse files
committed
Support all mount options in vue-test-utils
1 parent 1712eb3 commit 356d624

File tree

6 files changed

+56
-19
lines changed

6 files changed

+56
-19
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"babel-eslint": "^10.0.1",
4747
"babel-jest": "^23.6.0",
4848
"coveralls": "^3.0.2",
49-
"eslint": "^5.11.0",
49+
"eslint": "^5.11.1",
5050
"eslint-config-standard": "^12.0.0",
5151
"eslint-plugin-import": "^2.14.0",
5252
"eslint-plugin-node": "^8.0.0",

src/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import {
1313
const mountedWrappers = new Set()
1414

1515
function render (TestComponent, {
16-
props = null,
1716
store = null,
18-
routes = null
17+
routes = null,
18+
...mountOptions
1919
} = {}, configurationCb) {
2020
const localVue = createLocalVue()
2121
let vuexStore = null
@@ -39,13 +39,15 @@ function render (TestComponent, {
3939
configurationCb(localVue)
4040
}
4141

42+
const { props, ...rest } = mountOptions
4243
const wrapper = mount(TestComponent, {
4344
localVue,
4445
router,
4546
store: vuexStore,
4647
propsData: { ...props },
4748
attachToDocument: true,
48-
sync: false
49+
sync: false,
50+
...rest
4951
})
5052

5153
mountedWrappers.add(wrapper)

tests/__tests__/components/Button.vue

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
<template>
2-
<button :class="typeClass" @click="clicked">{{ text }}</button>
2+
<button
3+
:class="typeClass"
4+
@click="clicked"
5+
>{{ text }}</button>
36
</template>
47

58
<script>
69
export default {
710
props: {
811
text: {
912
type: String,
10-
default: '',
13+
default: ''
1114
},
1215
clicked: {
1316
type: Function,
1417
default: () => true
1518
},
1619
type: {
1720
validator: (value) => ['primary', 'secondary'].includes(value),
18-
},
19-
21+
default: 'primary'
22+
}
2023
},
2124
computed: {
22-
typeClass: function() {
25+
typeClass: function () {
2326
if (this.type) {
24-
return `button button--${this.type}`;
27+
return `button button--${this.type}`
2528
}
26-
return 'button';
27-
},
28-
},
29-
30-
};
31-
</script>
29+
return 'button'
30+
}
31+
}
32+
}
33+
</script>

tests/__tests__/components/Form.vue

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<template>
2+
<form>
3+
<label for="search">
4+
<FontAwesomeIcon icon="search"/> Search
5+
</label>
6+
<input
7+
id="search"
8+
type="text"
9+
name="search"
10+
>
11+
<VButton text="Search now" />
12+
</form>
13+
</template>
14+
15+
<script>
16+
import VButton from './Button'
17+
18+
export default {
19+
name: 'SearchForm',
20+
components: { VButton }
21+
}
22+
</script>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { render, cleanup } from '../../src'
2+
import Form from './components/Form'
3+
4+
afterEach(cleanup)
5+
6+
test('Form contains search button', () => {
7+
const { getByText } = render(Form, {
8+
stubs: ['FontAwesomeIcon']
9+
})
10+
getByText('Search now')
11+
})

tests/__tests__/simple-button.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { render, cleanup, fireEvent } from '../../src';
2-
import SimpleButton from './components/Button';
1+
import { render, cleanup, fireEvent } from '../../src'
2+
import SimpleButton from './components/Button'
33

44
afterEach(cleanup)
55

@@ -20,4 +20,4 @@ test('clicked prop is called when button is clicked', () => {
2020
})
2121
fireEvent.click(getByText(text))
2222
expect(clicked).toBeCalled()
23-
})
23+
})

0 commit comments

Comments
 (0)