Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Vue and Jest
import Vue from 'vue/dist/vue.js';
import Router from 'vue-router'
import Layout from '../../../src/layout.vue';
import About from '../../../src/pages/general/about.vue';
import Legal from '../../../src/pages/general/legal.vue';
describe('about', () => {
beforeEach(() => {
window.location = '/about';
document.body.innerHTML = `
<div id="app"></div>
`;
});
/**
* Test
*/
it('should render correct contents', async () => {
Vue.use(Router);
const router = new Router({
mode: 'history',
scrollBehavior: () => ({ y: 0 }),
routes: [
{ path: '/about', component: About },
{ path: '/legal', component: Legal },
{ path: '*', redirect: '/legal' }
]
});
const vm = new Vue({
el: '#app',
router: router,
...Layout
});
await Vue.nextTick(() => {});
console.log(document.body.innerHTML);
});
});
<script>
</script>
<template>
<div>
<router-link to="/">Index</router-link>
<p>About</p>
</div>
</template>
<script>
</script>
<template>
<div>
<transition name="router" mode="out-in">
<router-view></router-view>
</transition>
</div>
</template>
@alexlanz

This comment has been minimized.

Copy link
Owner Author

commented Jun 5, 2017

These are the error messages that I receive when I execute the tests.

console.error node_modules/vue/dist/vue.js:440
      [Vue warn]: Error in beforeCreate hook: "SyntaxError"

      (found in <Root>)
    console.error node_modules/vue/dist/vue.js:529
      SyntaxError
          at LocationImpl.replace (/vagrant/node_modules/jsdom/lib/jsdom/living/window/Location-impl.js:225:13)
          at Location.replace (/vagrant/node_modules/jsdom/lib/jsdom/living/generated/Location.js:39:29)
          at pushState (/vagrant/node_modules/vue-router/dist/vue-router.common.js:1525:52)
          at replaceState (/vagrant/node_modules/vue-router/dist/vue-router.common.js:1530:3)
          at HTML5History.ensureURL (/vagrant/node_modules/vue-router/dist/vue-router.common.js:1923:35)
          at /vagrant/node_modules/vue-router/dist/vue-router.common.js:1584:12
          at /vagrant/node_modules/vue-router/dist/vue-router.common.js:1660:7
          at step (/vagrant/node_modules/vue-router/dist/vue-router.common.js:1538:7)
          at step (/vagrant/node_modules/vue-router/dist/vue-router.common.js:1545:9)
          at runQueue (/vagrant/node_modules/vue-router/dist/vue-router.common.js:1549:3)
    console.error node_modules/vue/dist/vue.js:440
      [Vue warn]: Error in render function: "TypeError: Cannot read property 'matched' of undefined"

      (found in <Root>)
    console.error node_modules/vue/dist/vue.js:529
      TypeError: Cannot read property 'matched' of undefined
          at render (/vagrant/node_modules/vue-router/dist/vue-router.common.js:63:24)
          at createFunctionalComponent (/vagrant/node_modules/vue/dist/vue.js:3314:35)
          at createComponent (/vagrant/node_modules/vue/dist/vue.js:3464:12)
          at _createElement (/vagrant/node_modules/vue/dist/vue.js:3621:15)
          at createElement (/vagrant/node_modules/vue/dist/vue.js:3574:10)
          at vm._c (/vagrant/node_modules/vue/dist/vue.js:3865:42)
          at Proxy.render (/vagrant/scripts/src/layout.vue:20:212)
          at Vue$3.Vue._render (/vagrant/node_modules/vue/dist/vue.js:3901:22)
          at Vue$3.updateComponent (/vagrant/node_modules/vue/dist/vue.js:2443:21)
          at Watcher.get (/vagrant/node_modules/vue/dist/vue.js:2780:25)
          at new Watcher (/vagrant/node_modules/vue/dist/vue.js:2763:12)
          at mountComponent (/vagrant/node_modules/vue/dist/vue.js:2447:17)
          at Vue$3.Object.<anonymous>.Vue$3.$mount (/vagrant/node_modules/vue/dist/vue.js:7564:10)
          at Vue$3.Object.<anonymous>.Vue$3.$mount (/vagrant/node_modules/vue/dist/vue.js:9663:16)
          at Vue$3.Vue._init (/vagrant/node_modules/vue/dist/vue.js:4004:10)
          at new Vue$3 (/vagrant/node_modules/vue/dist/vue.js:4089:8)
          at _callee$ (/vagrant/scripts/tests/pages/general/about.test.js:36:34)
          at tryCatch (/vagrant/node_modules/regenerator-runtime/runtime.js:65:40)
          at GeneratorFunctionPrototype.invoke [as _invoke] (/vagrant/node_modules/regenerator-runtime/runtime.js:303:22)
          at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/vagrant/node_modules/regenerator-runtime/runtime.js:117:21)
          at step (/vagrant/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
          at /vagrant/node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14
          at Promise.F (/vagrant/node_modules/core-js/library/modules/_export.js:35:28)
          at Object.<anonymous> (/vagrant/node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12)
          at Object.<anonymous> (/vagrant/node_modules/jest-jasmine2/build/jasmine-async.js:42:32)
          at attemptAsync (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1984:24)
          at QueueRunner.run (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1939:9)
          at /vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1966:16
          at /vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1909:9
          at Object.fn (/vagrant/node_modules/jest-jasmine2/build/jasmine-async.js:68:11)
          at attemptAsync (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1984:24)
          at QueueRunner.run (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1939:9)
          at /vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1966:16
          at /vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1909:9
          at Object.fn (/vagrant/node_modules/jest-jasmine2/build/jasmine-async.js:68:11)
          at attemptAsync (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1984:24)
          at QueueRunner.run (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1939:9)
          at QueueRunner.execute (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1927:10)
          at Spec.queueRunnerFactory (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:716:35)
          at Spec.execute (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:372:10)
          at Object.fn (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:2584:37)
          at attemptAsync (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1984:24)
          at QueueRunner.run (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1939:9)
          at QueueRunner.execute (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1927:10)
          at queueRunnerFactory (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:716:35)
          at Object.fn (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:2569:13)
          at attemptAsync (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1984:24)
          at QueueRunner.run (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1939:9)
          at QueueRunner.execute (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:1927:10)
          at queueRunnerFactory (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:716:35)
          at TreeProcessor.execute (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:2431:7)
          at Env.execute (/vagrant/node_modules/jest-jasmine2/vendor/jasmine-2.5.2.js:778:17)
          at jasmine2 (/vagrant/node_modules/jest-jasmine2/build/index.js:95:7)
          at runTest (/vagrant/node_modules/jest-cli/build/runTest.js:53:10)
          at promise.then (/vagrant/node_modules/jest-cli/build/TestRunner.js:307:14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.