React Testing Fake Xmlhttprequest
I am writing some test code for someone's application. I am new to writing tests specifically for React. In one of the methods inside the component, a new XMLHttpRequest object is
Solution 1:
Finally got this working. Added this to the top. I'd imagine it should work with overriding any class.
varFakeXMLHTTPRequests = require('fakexmlhttprequest')
var requests = []
XMLHttpRequest = function() {
var r = newFakeXMLHTTPRequests(arguments)
requests.push(r)
return r
}
Thanks to this article for helping me to think this through. http://www.asbjornenge.com/wwc/testing_react_components.html
Can also so this for if using XMLHttpRequest: correct usage of sinon's fake XMLHttpRequest
Post a Comment for "React Testing Fake Xmlhttprequest"