Last active
June 6, 2019 18:45
-
-
Save manuelgeek/f373cb56882cebcf5f399bf9233e8a16 to your computer and use it in GitHub Desktop.
GTT unit test
This file contains hidden or 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 Router from 'vue-router' | |
import Hello from '@/components/Hello' | |
import List from '@/components/List' | |
Vue.use(Router) | |
export default new Router({ | |
routes: [ | |
{ | |
path: '/', | |
name: 'Hello', | |
component: Hello | |
}, | |
{ | |
path: '/to-do', | |
name: 'ToDo', | |
component: List | |
}, | |
] | |
}) |
This file contains hidden or 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 List from '@/components/List'; | |
import Vue from 'vue'; | |
describe('List.vue', () => { | |
it('displays items from the list', () => { | |
const Constructor = Vue.extend(List); | |
const ListComponent = new Constructor().$mount(); | |
expect(ListComponent.$el.textContent).to.contain('read Java'); | |
}) | |
it('adds a new item to list on click', () => { | |
// build component | |
const Constructor = Vue.extend(List); | |
const ListComponent = new Constructor().$mount(); | |
// set input value | |
ListComponent.newItem = 'do Laravel'; | |
// simulate click event | |
const button = ListComponent.$el.querySelector('button'); | |
const clickEvent = new window.Event('click'); | |
button.dispatchEvent(clickEvent); | |
ListComponent._watcher.run(); | |
// assert list contains new item | |
expect(ListComponent.$el.textContent).to.contain('do Laravel'); | |
expect(ListComponent.listItems).to.contain('do Laravel'); | |
}) | |
}) |
This file contains hidden or 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>My To Do List</h1> | |
</br> | |
<input v-model="newItem" > | |
<button @click="addItemToList">Add</button> | |
<!-- displays list --> | |
<ul> | |
<li v-for="item in listItems">{{ item }}</li> | |
</ul> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'test', | |
data () { | |
return { | |
listItems: ['read Java', 'do c#', 'debbug Js'], | |
newItem: '' | |
} | |
}, | |
methods: { | |
addItemToList() { | |
this.listItems.push(this.newItem); | |
this.newItem = ''; | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment