Created
November 28, 2017 10:59
-
-
Save khanhtdbse/5cd381f9b7669face114ca363560bca2 to your computer and use it in GitHub Desktop.
HelloWorld.vue
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 HelloWorld from '@/components/HelloWorld' | |
import ButtonComponent from '@/components/ButtonComponent' | |
describe('HelloWorld.vue', () => { | |
let vm | |
// Khoi tao bien moi khi chay test case | |
beforeEach(() => { | |
const Constructor = Vue.extend(HelloWorld) | |
vm = new Constructor().$mount() | |
}) | |
// Kiem tra noi dung the h1 | |
it('should render correct contents', () => { | |
expect(vm.$el.querySelector('h1').textContent) | |
.to.equal('Welcome to my first TDD :)') | |
}) | |
// Kiem tra bien count = 0 | |
it('should has correct init counter variable', () => { | |
expect(vm.$data.count).to.equal(0) | |
}) | |
// Kiem tra HelloWorld component co child component | |
it('should has child ButtonComponent', () => { | |
expect(vm.$options.components.ButtonComponent).to.contain(ButtonComponent) | |
}) | |
// Kiem tra ham increment | |
it('should increment count', () => { | |
vm.increment() | |
expect(vm.$data.count).to.equal(1) | |
}) | |
// Kiem tra ham decrement | |
it('should decrement count', () => { | |
vm.decrement() | |
expect(vm.$data.count).to.equal(-1) | |
}) | |
// Kiem tra khi click vao button increment | |
it('should increment count when click increment button', () => { | |
vm.$el.querySelector('.increment-button').click() | |
expect(vm.$data.count).to.equal(1) | |
}) | |
// Kiem tra khi click vao button decrement | |
it('should decrement count when click decrement button', () => { | |
vm.$el.querySelector('.decrement-button').click() | |
expect(vm.$data.count).to.equal(-1) | |
}) | |
}) |
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> | |
<h1>{{ msg }}</h1> | |
<h2>{{ count }}</h2> | |
<button-component | |
@incrementButtonHasBeenClicked="increment()" | |
@decrementButtonHasBeenClicked="decrement()" | |
/> | |
</div> | |
</template> | |
<script> | |
import ButtonComponent from './ButtonComponent.vue' | |
export default { | |
name: 'HelloWorld', | |
data () { | |
return { | |
msg: 'Welcome to my first TDD :)', | |
count: 0 | |
} | |
}, | |
components: { ButtonComponent }, | |
methods: { | |
increment() { | |
this.count++ | |
}, | |
decrement() { | |
this.count-- | |
}, | |
} | |
} | |
</script> | |
<!-- Add "scoped" attribute to limit CSS to this component only --> | |
<style scoped> | |
h1, h2 { | |
font-weight: normal; | |
} | |
ul { | |
list-style-type: none; | |
padding: 0; | |
} | |
li { | |
display: inline-block; | |
margin: 0 10px; | |
} | |
a { | |
color: #42b983; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment