did you find any answer? I'm facing the same issue... Maybe you can share a file with test for this component?
Jan 11, 2017
2
Level 2
How to test a vue component that has methods that do ajax calls
Using karma and jasmine. How do I properly write a test that runs a method like the following:
methods {
getAddress: function () {
Addresses.show()
.then((response) => {
if (response.error && response.code === 404) {
this.editAddress = true;
}
this.address = response;
});
}
}
Addresss.show() is calling an api to get an address. I've read that some people are faking the responses, but I don't know how to do that in this case. Any thoughts?
I tried changing the function getAddress() to take a parameter (Addresses) in which I'd call getAddress(Addresses), with a modified Addresses.show() method. But it still needs to return a promise, because the method getAddresses is using a .then to set the data.
Please or to participate in this conversation.