Open marlokessler opened 1 year ago
Hi there,
I was running into the same issue, and defineExpose
is no option in my opinion. I got my <script setup>
running by updating to Jest 29, in your case update these libraries:
"@types/jest": "^27.0.1",
"@vue/vue2-jest": "^27.0.0",
"babel-jest": "^27.0.6",
"jest": "^27.0.5",
"ts-jest": "^27.0.4",
I'm not sure, you may have to make sure that @vue/compiler-sfc
is there too, otherwise it will go into this catch block. In the same file, the processScriptSetup Function is not in your vue-jest 27.0.0, as far as I can see it came with 29.1.0 in September 2022
Hey, I also encountered this issue before, I upgraded to
"jest": "29.0.0",
"@vue/vue2-jest": "29.1.0",
"jest-environment-jsdom": "29.0.0"
and now my <setup script>
component tests are working. 🎉🎉🎉🎉
Other deps:
"vue-template-compiler": "^2.7.14",
"vue": "2.7.14"
Also I'm using Typescript with babel my jest.config.js
like below
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
transform: {
'.*\\.(vue)$': '@vue/vue2-jest',
}
@omrumbakitemiz I am also facing the same issue, even if my package.json configuration same as mentioned by you.
below ways can help us to resolve this
(wrapper.vm as any)._setupProxy.someMethod
not sure using _setupProxy
is the proper way or not.
import {shallowMount,createLocalVue} from '@vue/test-utils';
import VueCompositionApi from '@vue/composition-api';
const localVue = createLocalVue()
localVue.use(VueCompositionApi)
shallowMount(require('./component.vue').default, {
localVue,
});
Hey, I also encountered this issue before, I upgraded to
"jest": "29.0.0", "@vue/vue2-jest": "29.1.0", "jest-environment-jsdom": "29.0.0"
and now my
<setup script>
component tests are working. 🎉🎉🎉🎉Other deps:
"vue-template-compiler": "^2.7.14", "vue": "2.7.14"
Also I'm using Typescript with babel my
jest.config.js
like belowpreset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel', transform: { '.*\\.(vue)$': '@vue/vue2-jest', }
is that really solve the problem?
Hi there,
Issue Description
I'm having trouble running unit tests with the Vue setup api using
<script setup>
. When running, the error states :[Vue warn]: Property or method "msg" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
Background
I created a plain new Vue 2 project via the Vue cli, updated to Vue 2.7.14 and migrated the
Hello World
component to the setup api. After migration the test does not work anymore. Nevertheless, the app is still running in dev mode and can be build.The component now is:
Used Dependencies
Does anybody know what to do? Thank you a lot in advance!