Might be cleaner to use sinon to mock out XmlHttpRequest, instead: http://sinonjs.org/docs/#server