Permalink
Browse files

increment counter from api answer

  • Loading branch information...
trollepierre committed May 7, 2017
1 parent 08b4bcd commit dac8dd205f9bc2ab7905d9b4157bf1259fdac31a
Showing with 23 additions and 1 deletion.
  1. +3 −1 src/components/Hello.vue
  2. +20 −0 test/unit/specs/Hello.spec.js
View
@@ -41,8 +41,10 @@ export default {
},
incrementFromTheDice: function () {
this.$http.get('http://setgetgo.com/rollthedice/get.php')
.then((response) => {
this.counter += parseInt(response.body, 10)
})
}
}
}
</script>
@@ -111,5 +111,25 @@ describe('Hello.vue', () => {
// after
Vue.http.get.restore()
})
it('should call increment counter from API answer', () => {
// given
const promiseCall = sinon.stub(Vue.http, 'get').returnsPromise()
promiseCall.resolves({ body: '5' })
// construct vue
const Constructor = Vue.extend(Hello)
const vm = new Constructor({ data: { counter: 6 } }).$mount()
// when
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()
})
})
})

0 comments on commit dac8dd2

Please sign in to comment.