Commit 2d7b9455 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Fixed promise action binding and simplified callbacks spy

parent dbab076b
......@@ -14,32 +14,27 @@ const waitForAllCallsToFinish = (service, waitForCount, successCallback) => {
timer();
};
function mockServiceCall(service, response, shouldFail) {
function mockServiceCall(service, response, shouldFail = false) {
const action = shouldFail ? Promise.reject : Promise.resolve;
const responseObject = response;
if (!responseObject.headers) responseObject.headers = {};
service.fetch.calls.reset();
service.fetch.and.callFake(() => action(responseObject));
service.fetch.and.callFake(action.bind(Promise, responseObject));
}
fdescribe('Poll', () => {
describe('Poll', () => {
const service = jasmine.createSpyObj('service', ['fetch']);
let callbacks;
beforeEach(() => {
callbacks = {
success: () => {},
error: () => {},
};
const callbacks = jasmine.createSpyObj('callbacks', ['success', 'error']);
spyOn(callbacks, 'success');
spyOn(callbacks, 'error');
afterEach(() => {
callbacks.success.calls.reset();
callbacks.error.calls.reset();
service.fetch.calls.reset();
});
fit('calls the success callback when no header for interval is provided', (done) => {
mockServiceCall(service, { status: 200 });
it('calls the success callback when no header for interval is provided', (done) => {
mockServiceCall(service, { status: 200 }, false);
new Poll({
resource: service,
......@@ -53,7 +48,7 @@ fdescribe('Poll', () => {
expect(callbacks.error).not.toHaveBeenCalled();
done();
}, 0);
});
});
it('calls the error callback whe the http request returns an error', (done) => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment