Hi,
I am trying to test for the bad path of my XMLHttpRequest (plain
JavaScript one, not any library) processing function with jasmine, and
the best I can think about is this:
describe("LoadFeed", function() {
beforeEach(function() {
spyOn(XMLHttpRequest.prototype, 'open').andCallThrough();
spyOn(XMLHttpRequest.prototype, 'send');
});
// ...
it("should fail when XMLHttpRequest fails", function() {
spyOn(XMLHttpRequest.prototype, 'onerror').andCallThrough();
spyOn(XMLHttpRequest.prototype,
'onload').andCallFake(function(evt) {
var new_event = document.createEvent("ProgressEvents");
new_event.initProgressEvent("error", evt.canBubble,
evt.cancelable, evt.lengthComputable, evt.loaded,
evt.lengthComputable);
evt.target.dispatchEvent(new_event);
podcast.load_feed(URL_FEED);
expect(XMLHttpRequest.prototype.onerror).toHaveBeenCalled();
});
});
However, when I try to run this I get this error:
TypeError: Value does not implement interface
XMLHttpRequestEventTarget. in
file:///home/matej/projekty/elasmotherium/wsgi\
/static/spec/lib/jasmine.js (line 2415)
Any idea, how to do it right?
Thanks for any response,
Matěj
--
http://www.ceplovi.cz/matej/, Jabber: mcepl<at>
ceplovi.cz
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
In those days spirits were brave, the stakes were high, men were
real men, women were real women and small furry creatures from
Alpha Centauri were real small furry creatures from Alpha
Centauri.
-- Douglas Adams