-
Notifications
You must be signed in to change notification settings - Fork 130
Open
Labels
Description
I'll start by saying thanks for an awesome bit of software. I've been having a lot of fun using jasmine and jasmine-ajax.
I'm testing a polling engine that wraps XMLHttpRequest, and want to test that the responseType specified will return the correct type (i.e. if I specify type 'json', xhr.response should be an object). Here's what I'm trying to do:
describe('response types', function() {
it('parses a response based on its type', function() {
var dataHandler = jasmine.createSpy('success');
pollr.on('data', dataHandler);
pollr.responseType = 'json';
pollr.start();
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200,
'response': '{message: "ok"}'
});
expect(dataHandler).toHaveBeenCalledWith({ message: 'ok'});
});
});I know this is flawed because after logging a few real xhrs it seems like my browser parses the json before xhr.response is available, and a realistic response would have an object in the response field. But since a real xhr parses a response based on responseType, I (probably naively) think that jasmine-ajax should somehow do the same. Thanks again.
Reactions are currently unavailable