Jasmine-Ajax and Vue Resource
See original GitHub issueHello, i’m trying to unit test my vue-resource ajax requests but jasmine-ajax does not seem to be able to picking up and intercepting the ajax request. I had jasmine-ajax working when i use jQuery ajax, but this doenst seem to be playing ball.
My Code:
it('should use the delete method', function(){
var vm = new Vue({
template: '<div><test :status="status" :entity="entity" :detailspage="" :user="user" v-ref:action-comp></test></div>',
components: {
'test': Action
},
data: {
status: 'processing',
entity: {entity_id: '123'},
user: 'standard'
}
}).$mount();
vm.$refs.actionComp.cancelItem(vm.entity, 'true');
var request = jasmine.Ajax.requests.mostRecent();
expect(request.method).toEqual('DELETE');
});
/* my vue-resource */
vm.$http.delete('/api-url/' + entity.entity_id)
.then(function (res){
entity.status = 'cancelled';
vm.getUpdatedList();
}, function (res) {
console.log('testing error');
});`
it just does not intercept so the error is always fired.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8
Top Results From Across the Web
Vue 2 Unit Testing Primer - Medium
This article will take you through the process of building and testing a small Vue 2 application with Jasmine.
Read more >Sending AJAX Requests in Vue.js - Stack Abuse
Vue.js has an official package which is called vue-resource which works as an HTTP client, but the official documentation suggests using Axios.
Read more >vue-resource | Yarn - Package Manager
The plugin for Vue.js provides services for making web requests and handle responses using a XMLHttpRequest or JSONP. Features. Supports the Promise API...
Read more >Replace vue-resource and $.ajax with axios to be the default HTTP ...
Replace vue-resource with axios; Update docs; Replace $.ajax with axios - not as ... we depend on karma-jasmine which depends on jQuery, but...
Read more >AJAX Requests in Vue.js: Axios vs vue-resource vs fetch
AJAX Requests in Vue.js: Axios vs vue-resource vs fetch. Consuming data from remote API servers via API calls, HTTP requests or Ajax ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Why was this closed? This appears to be an ongoing issue.
I am searching in the same area. My tests are running with karma+webpack+mocha+sinonjs (This is how the large vue webpack template sets up everything.) And I have the same problem with vue-resource.
In sinon.js one can setup a
sinon.fakeServer.create()
that should intercept all AJAX calls, but for some reasons, it does not intercept the calls by vue-resource. Somehow vue-resource fiddles areound with XMLHttpRequest on its own.The only way I got it working was with another method, by using vue-resource’s own
interceptor
like this in my test spec:I’d assume that
jasmine.Ajax.request
hangs on the same problem thansinon.fakeServer
.