Created
December 9, 2016 15:01
-
-
Save potato4d/b5a9ae9285b5329225c591fefeefd809 to your computer and use it in GitHub Desktop.
Vue.js Vueコンポーネントのユニットテストを書いてみよう ref: http://qiita.com/potato4d/items/8215941b84c11b845886
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' | |
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.') | |
}) | |
}) |
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
<template lang="html"> | |
<div> | |
</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
<template> | |
<div> | |
+++ <p>Hello, {{ person }}.</p> | |
</div> | |
</template> | |
+++ <script> | |
+++ export default { | |
+++ props: ["person"] | |
+++ } | |
+++ </script> |
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
$ 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