Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7cb193

Browse files
authored
Merge pull request #13 from dfcook/mount-options
Support all mount options in vue-test-utils
2 parents 1712eb3 + d4d8755 commit e7cb193

File tree

9 files changed

+66
-26
lines changed

9 files changed

+66
-26
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ The `render` function takes up to 3 parameters and returns an object with some h
116116

117117
1. Component - the Vue component to be tested.
118118
2. RenderOptions - an object containing additional information to be passed to @vue/test-utils mount. This can be:
119-
* props - The component props to be passed to TestComponent
120119
* store - The object definition of a Vuex store, if present `render` will configure a Vuex store and pass to mount.
121120
* routes - A set of routes, if present render will configure VueRouter and pass to mount.
121+
All additional render options are passed to the vue-test-utils mount function in its options.
122122
3. configurationCb - A callback to be called passing the Vue instance when created. This allows 3rd party plugins to be installed prior to mount.
123123

124124
### fireEvent

‎package.json‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 9 additions & 4 deletions
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,18 @@ function render (TestComponent, {
3939
configurationCb(localVue)
4040
}
4141

42+
if (!mountOptions.propsData && !!mountOptions.props) {
43+
mountOptions.propsData = mountOptions.props
44+
delete mountOptions.props
45+
}
46+
4247
const wrapper = mount(TestComponent, {
4348
localVue,
4449
router,
4550
store: vuexStore,
46-
propsData: { ...props },
4751
attachToDocument: true,
48-
sync: false
52+
sync: false,
53+
...mountOptions
4954
})
5055

5156
mountedWrappers.add(wrapper)
Lines changed: 14 additions & 12 deletions
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‎

Lines changed: 22 additions & 0 deletions
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>

‎tests/__tests__/fetch.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('Fetch makes an API call and displays the greeting when load-greeting is cl
1010
})
1111
)
1212

13-
const { html, getByText } = render(Fetch, { props: { url: '/greeting' } })
13+
const { html, getByText } = render(Fetch, { propsData: { url: '/greeting' } })
1414

1515
// Act
1616
await fireEvent.click(getByText('Fetch'))
Lines changed: 11 additions & 0 deletions
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‎

Lines changed: 3 additions & 3 deletions
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+
})

‎yarn.lock‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,10 +1873,10 @@ eslint-visitor-keys@^1.0.0:
18731873
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"
18741874
integrity sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==
18751875

1876-
eslint@^5.11.0:
1877-
version "5.11.0"
1878-
resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.11.0.tgz#51a0e70f137a425fe044cd48273b96f28a774b1f"
1879-
integrity sha512-gbEg0ttToZPkZUv2yYjpipxuYrv/9aSSmgM4V6GkiO3u04QosHYBtduUCqLEulEg3YvNDAkk3OWzyQJ/heZ3Nw==
1876+
eslint@^5.11.1:
1877+
version "5.11.1"
1878+
resolved "https://registry.yarnpkg.com/eslint/-/eslint-5.11.1.tgz#8deda83db9f354bf9d3f53f9677af7e0e13eadda"
1879+
integrity sha512-gOKhM8JwlFOc2acbOrkYR05NW8M6DCMSvfcJiBB5NDxRE1gv8kbvxKaC9u69e6ZGEMWXcswA/7eKR229cEIpvg==
18801880
dependencies:
18811881
"@babel/code-frame" "^7.0.0"
18821882
ajv "^6.5.3"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /