Unable to get jest working with route on Vue 2.7.14 #682
-
Ziggy version1.6.2 Laravel version9.52.16 DescriptionHi, I got a very simple test, but I'm unable to make it work, it constantly says that the Here's my test and my last try. import { createLocalVue, mount } from '@vue/test-utils'
import AdgemButton from '@/Components/Common/AdgemButton.vue';
import TableConfigurationModal from '@/Components/Modal/TableConfigurationModal.vue';
import { ZiggyVue } from 'ziggyvue';
import { Ziggy } from '../../../../resources/js/ziggy';
const localVue = createLocalVue()
localVue.use(ZiggyVue, Ziggy.routes)
test('adgem button is succesfully rendered with clasess', () => {
const wrapper = mount(TableConfigurationModal, {
localVue,
})
expect(wrapper.text()).toContain('Hello world')
}) Here's my // jest.config.js
module.exports = {
"roots": [
"<rootDir>/tests/Vue"
],
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/resources/js/$1",
"axios": "axios/dist/node/axios.cjs",
"^ziggyvue$": "<rootDir>/vendor/tightenco/ziggy/dist/vue",
},
"moduleFileExtensions": [ 'js', 'json', 'vue' ],
"setupFilesAfterEnv": [
"<rootDir>tests/Vue/setup.js"
],
"testEnvironment": "jsdom",
} And here's the trace of the error: Details
adgem button is succesfully rendered with clasess
Ziggy call and contextJest tests are failing on the route helper. Ziggy configurationNot able to print this info Route definitionNot a route issue |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Can you share the contents of your There's one problem in your test setup but I don't think it's related—you need to pass the whole - localVue.use(ZiggyVue, Ziggy.routes)
+ localVue.use(ZiggyVue, Ziggy) |
Beta Was this translation helpful? Give feedback.
Within the
<script>
tags of your Vue components the route function is available as a mixin, so it'sthis.route()
not justroute()
. That should fix this but let me know if it doesn't!