Skip to content

Alternative approach for integration with Vuetify #123

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 4 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
7 changes: 7 additions & 0 deletions src/__tests__/components/Vuetify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
<v-card-text>Lorem ipsum dolor sit amet.</v-card-text>
</v-card>
</v-dialog>
<span v-if="showHint">This is a hint</span>
</v-app>
</template>

<script>
export default {
name: 'VuetifyDemoComponent',
props: {
showHint: {
type: Boolean,
default: false,
},
},
data() {
return {
show: false,
Expand Down
27 changes: 16 additions & 11 deletions src/__tests__/vuetify.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,18 @@ import VuetifyDemoComponent from './components/Vuetify'
// https://vuetifyjs.com/en/getting-started/unit-testing
Vue.use(Vuetify)

// Custom render wrapper to integrate Vuetify with Vue Testing Library.
// Custom container to integrate Vuetify with Vue Testing Library.
// Vuetify requires you to wrap your app with a v-app component that provides
// a <div data-app="true"> node.
const renderWithVuetify = (component, options, callback) => {
return render(
// anonymous component
component,
{
// Vue's render function
render(createElement) {
// wrap the component with a <div data-app="true"> node and render the test component
return createElement('div', {attrs: {'data-app': true}}, [
createElement(component),
])
},
container: document.createElement('div').setAttribute('data-app', 'true'),
// for Vuetify components that use the $vuetify instance property
vuetify: new Vuetify(),
...options,
},
// for Vuetify components that use the $vuetify instance property
{vuetify: new Vuetify(), ...options},
callback,
)
}
Expand All @@ -44,3 +39,13 @@ test('renders a Vuetify-powered component', async () => {
</div>
`)
})

test('allows changing props', async () => {
const {queryByText, updateProps} = renderWithVuetify(VuetifyDemoComponent)

expect(queryByText('This is a hint')).toBe(null)

await updateProps({showHint: true})

expect(queryByText('This is a hint')).not.toBe(null)
})