Created
June 5, 2017 06:18
-
-
Save alexlanz/c751debbcc8a37c11fd78054e9c615e9 to your computer and use it in GitHub Desktop.
Vue and Jest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
</script> | |
<template> | |
<div> | |
<router-link to="/">Index</router-link> | |
<p>About</p> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
</script> | |
<template> | |
<div> | |
<transition name="router" mode="out-in"> | |
<router-view></router-view> | |
</transition> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
</script> | |
<template> | |
<div> | |
<router-link to="/">Index</router-link> | |
<p>Legal</p> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These are the error messages that I receive when I execute the tests.