Skip to content

Instantly share code, notes, and snippets.

@potato4d
Created December 9, 2016 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potato4d/b5a9ae9285b5329225c591fefeefd809 to your computer and use it in GitHub Desktop.
Save potato4d/b5a9ae9285b5329225c591fefeefd809 to your computer and use it in GitHub Desktop.
Vue.js Vueコンポーネントのユニットテストを書いてみよう ref: http://qiita.com/potato4d/items/8215941b84c11b845886
import Vue from 'vue'
import Greeting from 'src/components/Greeting.vue'
function getInstance (Component, propsData) {
const Ctor = Vue.extend(Component)
const vm = new Ctor({ propsData }).$mount()
return vm
}
describe('Greeting.vue', () => {
it('<p> tag content equal props data `person`', () => {
const instance = getInstance(Greeting, {person: 'john'});
expect(instance.$el.querySelector("p").textContent)
.to.equal('Hello, john.')
})
})
<template lang="html">
<div>
</div>
</template>
<template>
<div>
+++ <p>Hello, {{ person }}.</p>
</div>
</template>
+++ <script>
+++ export default {
+++ props: ["person"]
+++ }
+++ </script>
$ npm run test
.
.
.
Greeting.vue
✓ <p> tag content equal props data `person`
TOTAL: 2 SUCCESS
=============================== Coverage summary ===============================
Statements : 100% ( 11/11 )
Branches : 100% ( 4/4 ), 1 ignored
Functions : 100% ( 2/2 )
Lines : 100% ( 5/5 )
================================================================================
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment