File size: 1,765 Bytes
5fae594 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
describe("streamingHttp", function(){
"use strict";
describe("calls through to browser xhr", function(){
it('gives xhr null when body is null', function(){
var eventBus = pubSub(), xhr = xhrStub();
streamingHttp(eventBus, xhr, 'GET', 'http://example.com', null);
expect( xhr.send ).toHaveBeenCalledWith(null);
})
it('give xhr string request body', function(){
var eventBus = pubSub(), xhr = xhrStub();
streamingHttp(eventBus, xhr, 'GET', 'http://example.com', 'my_data');
expect( xhr.send ).toHaveBeenCalledWith('my_data');
})
it('gives xhr the request headers', function(){
var eventBus = pubSub(), xhr = xhrStub();
var headers = {
'X-FROODINESS':'frood',
'X-HOOPINESS':'hoopy'
};
streamingHttp(eventBus, xhr, 'GET', 'http://example.com', undefined, headers);
expect( xhr.setRequestHeader ).toHaveBeenCalledWith( 'X-FROODINESS', 'frood' );
expect( xhr.setRequestHeader ).toHaveBeenCalledWith( 'X-HOOPINESS', 'hoopy' );
});
it('should be able to abort an xhr once started', function(){
var eventBus = pubSub(), xhr = xhrStub();
streamingHttp(eventBus, xhr, 'GET', 'http://example.com', 'my_data');
eventBus(ABORTING).emit();
expect( xhr.abort ).toHaveBeenCalled();
});
function xhrStub() {
return jasmine.createSpyObj('xhr', ['abort', 'open', 'setRequestHeader', 'send']);
}
});
});
|