-
Notifications
You must be signed in to change notification settings - Fork 157
Closed
Description
Describe the bug
When using the <script setup>
syntax sugar the Vue test utils throws an error. This is not a problem if using the regular syntax. Using Test Utils 2.0.0
Reproduction
Reproduction link:
https://github.com/martinszeltins/Vue-test-utils-vite-setup-error
Given that we have a Button component using <script setup>
<template>
<div class="button">
<div
class="button__content">
{{ msg }}
My button
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
const msg = ref('Hello')
</script>
And we create a test for it - then it throws and error
import { shallowMount } from '@vue/test-utils'
import Button from '@/components/Button.vue'
describe('Button.vue', () => {
it('passes this test', () => {
const wrapper = shallowMount(Button)
expect(wrapper.text()).toMatch('My button')
})
})
It throws an error
FAIL tests/unit/example.spec.js
Button.vue
✕ passes this test (33ms)
● Button.vue › passes this test
TypeError: Cannot read property 'subTree' of undefined
5 | it('passes this test', () => {
6 | const wrapper = shallowMount(Button)
> 7 | expect(wrapper.text()).toMatch('My button')
| ^
8 | })
9 | })
10 |
at VueWrapper.get [as hasMultipleRoots] (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:1911:30)
at VueWrapper.get [as element] (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:1926:25)
at VueWrapper.text (node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:1967:27)
at Object.<anonymous> (tests/unit/example.spec.js:7:20)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
System Info
- required
vite
version: 1.0.0-rc.13 - required Operating System: Ubuntu Linux
- required Node version: 12.18.2
- Optional:
- npm version: 6.14.8
- Installed
vue
version: 3.0.3 - Installed
@vue/compiler-sfc
version: 3.03
Metadata
Metadata
Assignees
Labels
No labels