Skip to content

Support all mount options in vue-test-utils #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"coveralls": "^3.0.2",
"eslint": "^5.11.0",
"eslint": "^5.11.1",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^8.0.0",
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
const mountedWrappers = new Set()

function render (TestComponent, {
props = null,
store = null,
routes = null
routes = null,
...mountOptions
} = {}, configurationCb) {
const localVue = createLocalVue()
let vuexStore = null
Expand All @@ -39,13 +39,15 @@ function render (TestComponent, {
configurationCb(localVue)
}

const { props, ...rest } = mountOptions
const wrapper = mount(TestComponent, {
localVue,
router,
store: vuexStore,
propsData: { ...props },
attachToDocument: true,
sync: false
sync: false,
...rest
})

mountedWrappers.add(wrapper)
Expand Down
26 changes: 14 additions & 12 deletions tests/__tests__/components/Button.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<template>
<button :class="typeClass" @click="clicked">{{ text }}</button>
<button
:class="typeClass"
@click="clicked"
>{{ text }}</button>
</template>

<script>
export default {
props: {
text: {
type: String,
default: '',
default: ''
},
clicked: {
type: Function,
default: () => true
},
type: {
validator: (value) => ['primary', 'secondary'].includes(value),
},

default: 'primary'
}
},
computed: {
typeClass: function() {
typeClass: function () {
if (this.type) {
return `button button--${this.type}`;
return `button button--${this.type}`
}
return 'button';
},
},

};
</script>
return 'button'
}
}
}
</script>
22 changes: 22 additions & 0 deletions tests/__tests__/components/Form.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<form>
<label for="search">
<FontAwesomeIcon icon="search"/> Search
</label>
<input
id="search"
type="text"
name="search"
>
<VButton text="Search now" />
</form>
</template>

<script>
import VButton from './Button'

export default {
name: 'SearchForm',
components: { VButton }
}
</script>
11 changes: 11 additions & 0 deletions tests/__tests__/integration-with-stubs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render, cleanup } from '../../src'
import Form from './components/Form'

afterEach(cleanup)

test('Form contains search button', () => {
const { getByText } = render(Form, {
stubs: ['FontAwesomeIcon']
})
getByText('Search now')
})
6 changes: 3 additions & 3 deletions tests/__tests__/simple-button.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, cleanup, fireEvent } from '../../src';
import SimpleButton from './components/Button';
import { render, cleanup, fireEvent } from '../../src'
import SimpleButton from './components/Button'

afterEach(cleanup)

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