Questions tagged [jasmine-ajax]

18 questions
5
votes
1 answer

Is it possible to mock an ajax request with jasmine simulating a network failure?

I have a web app that needs to check if the user is connected to the internet. In the implementation, the check() function promises to true if an ajax ping to a known endpoint succeeds and false if the ajax call fails in any way. In Jasmine, I can…
Robin
  • 698
  • 6
  • 25
4
votes
1 answer

Property 'Ajax' does not exist on type 'typeof jasmine'

I'm trying to install the jasmine plugin "jasmine-ajax" in an angular-cli project. The instructions seem pretty standard, but I keeping getting this error: "ERROR in src/app/app.component.spec.ts(8,13): error TS2339: Property 'Ajax' does not exist…
tuuk79
  • 51
  • 5
3
votes
0 answers

header Content-Type case sensitivity issue in testing with superagent and jasmine-ajax

I'm using superagent and jasmine-ajax in my testing environment (karma with jasmine adapter). I noticed an issue pertaining to case-sensitivity on the response headers when trying to mock responses that superagent will then handle. Testing…
awei
  • 1,154
  • 10
  • 26
2
votes
1 answer

How do I use jasmine-ajax to verify that the send method was called?

Should jasmine-ajax call onreadystatechange with a readyState of 4 if I never call the send method? If the above is not the expected behavior, how do I use jasmine-ajax to verify that the send method was called? Here is the code under test: …
Zack
  • 6,232
  • 8
  • 38
  • 68
2
votes
0 answers

jQuery AJAX call returns data wrapped in array while testing with Jasmine

I am pretty new to Jasmine testing so maybe I am doing something wrong. The problem is that I have simple AJAX call using jQuery. The method is simple: function sendSomeDataViaAJAX( link, data ) { $.ajax(link, { dataType: 'json', method: 'post',…
Chlebik
  • 646
  • 1
  • 9
  • 27
1
vote
0 answers

Using Jasmine with AJAX to load data does not seem to save it to the javascript class

I'm using Jasmine 2.8 with the jasmine-ajax plugin mock a jQuery getJSON call. The callback is supposed to store the data back in the object. I have a class structure as follows. // --------- settings.js ------------ class settings{ …
Wanderer
  • 544
  • 1
  • 7
  • 23
1
vote
1 answer

Set response headers in jasmine-ajax mock responses?

How do I set the response headers in respondWith with jasmine-ajax?
Filip Haglund
  • 13,919
  • 13
  • 64
  • 113
1
vote
0 answers

PhantomJS with Jasmine Ajax wont cause fail

I am trying to test the failure functionality of my ajax code (link). I am using the latest versions of Karma, PhantomJS, and Jasmine with all required plugins. The test run with success in Chrome but when I use PhantomJS my ajax fail tests do not…
1
vote
0 answers

how to test and mock an xmlhttprequest returning an arraybuffer

I have an angular app where a user can select a file from their dropbox account and then the application downloads the file. Here's the code. $scope.$watchCollection('dropBoxFiles', function (newDBFiles) { $scope.invalidResume = false; if…
geoff swartz
  • 5,437
  • 11
  • 51
  • 75
1
vote
3 answers

How to correctly use the mock-ajax library with Jasmine

I have a function which calls out for JSON and then in the success function makes some changes to the DOM. I'm trying to use the mock-ajax library in my Jasmine tests to avoid having to expose the various private functions for mocking. Even though…
Paul D'Ambra
  • 7,629
  • 3
  • 51
  • 96
0
votes
1 answer

Mock XMLHttpRequest using jasmine-ajax gives jasmine.ajax = undefined

I'm trying to mock a XMLHttpRequest in a unit test using jasmine-ajax. I have used Aurelia CLI to generate my application and I'm using Karma as the unit test runner. For the unit test I have tried importing jasmine-ajax: import * as jasmine from…
0
votes
0 answers

Can the jQuery ajax success function hold 'undefined' as data?

In the process of adding unit test coverage to existing javascript code we've encountered a case which we cannot seem to cover well, namely the code that checks for the callback's data to be undefined: $.ajax({ dataType: "json", url:…
Spork
  • 1,631
  • 1
  • 21
  • 37
0
votes
3 answers

Mocking jQuery ajax calls with Jasmine

I am using Jasmine 2.5.2 to write unit tests for code that performs Ajax requests using jQuery 3.1.1 . I would like to mock out the Ajax call, providing my own response status and text. I am using the Jasmine ajax plug-in…
Lozzer
  • 155
  • 2
  • 12
0
votes
1 answer

Can't stop jasmine-ajax from trying to parse FormData object

I'm making a POST with AJAX and trying to test the data that gets sent, but I'm getting the error "paramString.split is not a function" when that test runs. I've looked for other posts about this but they all seem to be about getting FormData to…
js225
  • 3
  • 4
0
votes
1 answer

jasmine-ajax mock get parameters

I am using jasmine-ajax to mock $.ajax get calls. In my actual code I send some parameters through the data options. var request = $.ajax("/users", { data: {id:"1"}, }); but in my tests jasmine.Ajax.requests.mostRecent().url returns…
Vishnu
  • 4,377
  • 7
  • 26
  • 40
1
2