Jasmine Xmlhttprequest
Download mock ajaxjs and add it to your project.
Jasmine xmlhttprequest. Another alternative would be to mock the xmlhttprequest object ourselves. Jasmine ajax is currently compatible with any library that uses xmlhttprequest. Now we can write the first test. You can then requirejasmine ajax inside your test suite and access it via the jasmine global.
But we dont want to be doing this every time. In short theres something about dependency import problems in jasmine tests for angular that sometimes causes the real errors to be eaten. Readystate this. Xmlhttprequest exception 101 i checked my service logs and it seems like service is not getting any request.
Declare a variable in describe to make it available in all the it nodes. Install jasmine ajax from npm via npm install save dev jasmine ajax. Var xhr new xmlhttprequest. The command to do that is ng test source mapfalse.
Jasmine ajax mocks out your request at the xmlhttprequest object so should be compatible with other libraries that do ajax requests. By saving the values into thisxhr and thisrequests they are available to be used elsewhere within the test case. Javascript ajax xmlhttprequest phantomjs. So if you find yourself wondering about why youre getting that strange xmlhttprequest error try running your test suite without source maps.
Before each test we enable a fake xmlhttprequest and put each created request into an array. It also adds more overhead to our testing which already has a tendency to be left behind regardless of how straight forward it is. Jasmine has a module called jasmine ajax which makes testing xhr requests a.