Permalink
Browse files

reinit counter when API rejects error

  • Loading branch information...
trollepierre committed May 7, 2017
1 parent dac8dd2 commit fd3882674329cb7c0f15272fa4e22c42d2572733
Showing with 23 additions and 2 deletions.
  1. +4 −1 src/components/Hello.vue
  2. +19 −1 test/unit/specs/Hello.spec.js
View
@@ -1,6 +1,6 @@
<template>
<div class="hello">
<click-me-button ref="click-me-button" message="Increment counter" v-on:buttonHasBeenClicked="incrementCounter"></click-me-button>
<click-me-button message="Increment counter" v-on:buttonHasBeenClicked="incrementCounter"></click-me-button>
<div class="counter">{{ counter }}</div>
<h1>{{ msg }}</h1>
<h2>Essential Links</h2>
@@ -43,6 +43,9 @@ export default {
this.$http.get('http://setgetgo.com/rollthedice/get.php')
.then((response) => {
this.counter += parseInt(response.body, 10)
}, () => {
console.log('La Base semble être KO !')
this.counter = 0
})
}
}
@@ -125,11 +125,29 @@ describe('Hello.vue', () => {
vm.incrementFromTheDice()
// then
expect(promiseCall).to.have.been.calledWith('http://setgetgo.com/rollthedice/get.php')
expect(vm.$data.counter).to.equal(11)
// after
Vue.http.get.restore()
})
it('should reinit counter when api rejects error', () => {
// given
const promiseCall = sinon.stub(Vue.http, 'get').returnsPromise()
promiseCall.rejects()
// construct vue
const Constructor = Vue.extend(Hello)
const vm = new Constructor({ data: { counter: 6 } }).$mount()
// when
vm.incrementFromTheDice()
// then
expect(vm.$data.counter).to.equal(0)
// after
Vue.http.get.restore()
})
})
})

0 comments on commit fd38826

Please sign in to comment.