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) => { ...@@ -14,32 +14,27 @@ const waitForAllCallsToFinish = (service, waitForCount, successCallback) => {
timer(); timer();
}; };
function mockServiceCall(service, response, shouldFail) { function mockServiceCall(service, response, shouldFail = false) {
const action = shouldFail ? Promise.reject : Promise.resolve; const action = shouldFail ? Promise.reject : Promise.resolve;
const responseObject = response; const responseObject = response;
if (!responseObject.headers) responseObject.headers = {}; if (!responseObject.headers) responseObject.headers = {};
service.fetch.calls.reset(); service.fetch.and.callFake(action.bind(Promise, responseObject));
service.fetch.and.callFake(() => action(responseObject));
} }
fdescribe('Poll', () => { describe('Poll', () => {
const service = jasmine.createSpyObj('service', ['fetch']); const service = jasmine.createSpyObj('service', ['fetch']);
let callbacks; const callbacks = jasmine.createSpyObj('callbacks', ['success', 'error']);
beforeEach(() => {
callbacks = {
success: () => {},
error: () => {},
};
spyOn(callbacks, 'success'); afterEach(() => {
spyOn(callbacks, 'error'); 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) => { it('calls the success callback when no header for interval is provided', (done) => {
mockServiceCall(service, { status: 200 }); mockServiceCall(service, { status: 200 }, false);
new Poll({ new Poll({
resource: service, resource: service,
...@@ -53,7 +48,7 @@ fdescribe('Poll', () => { ...@@ -53,7 +48,7 @@ fdescribe('Poll', () => {
expect(callbacks.error).not.toHaveBeenCalled(); expect(callbacks.error).not.toHaveBeenCalled();
done(); done();
}, 0); });
}); });
it('calls the error callback whe the http request returns an error', (done) => { 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