Hi there,
I'm a little new to JavaScript testing so this may be quite the wrong approach to testing. With that said ;)
I'm using vue-js and vue-resource (
https://github.com/vuejs/vue-resource/) . The code I'm trying to test (a vue-js component) has a download function which looks like this:
download: function() {
this.$
http.post('/items/' +
this.cast.id + '/download.json')
.then(response => {
this.cast.state = 'downloading'
}, error => {
this.error = 'Could not fetch casts from server!'
})
}
I am mocking out the post in my test, but I can't work out how to assert _after_ the "then" has returned. I am using Jasmine2, and I have tried passing the `done` callback around - but still, I'm missing something.
it('should change the state to downloading if download called', () => {
<snip, setup for intercepting the ajax call>
testComponent.download()
// how to ensure that the "then" has been called (and state changed) before moving on to the assert?
expect(testComponent.cast.state).toBe('downloading');
});
});
If I add in console.logs I can see that the "then" part is being called after the call to "expect"
Apologies if this betrays some basic misunderstanding of how to test - but pointers would be really appreciated. I've seen quite a few examples of testing promises themselves, but all I really want to do is to call a method and wait until the promise has been fulfilled.
Thanks!
Patrick