summaryrefslogtreecommitdiff
path: root/spec/frontend/lib/utils/poll_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/lib/utils/poll_spec.js')
-rw-r--r--spec/frontend/lib/utils/poll_spec.js60
1 files changed, 21 insertions, 39 deletions
diff --git a/spec/frontend/lib/utils/poll_spec.js b/spec/frontend/lib/utils/poll_spec.js
index 861808e3ad8..1f150599983 100644
--- a/spec/frontend/lib/utils/poll_spec.js
+++ b/spec/frontend/lib/utils/poll_spec.js
@@ -50,58 +50,48 @@ describe('Poll', () => {
};
});
- it('calls the success callback when no header for interval is provided', (done) => {
+ it('calls the success callback when no header for interval is provided', () => {
mockServiceCall({ status: 200 });
setup();
- waitForAllCallsToFinish(1, () => {
+ return waitForAllCallsToFinish(1, () => {
expect(callbacks.success).toHaveBeenCalled();
expect(callbacks.error).not.toHaveBeenCalled();
-
- done();
});
});
- it('calls the error callback when the http request returns an error', (done) => {
+ it('calls the error callback when the http request returns an error', () => {
mockServiceCall({ status: 500 }, true);
setup();
- waitForAllCallsToFinish(1, () => {
+ return waitForAllCallsToFinish(1, () => {
expect(callbacks.success).not.toHaveBeenCalled();
expect(callbacks.error).toHaveBeenCalled();
-
- done();
});
});
- it('skips the error callback when request is aborted', (done) => {
+ it('skips the error callback when request is aborted', () => {
mockServiceCall({ status: 0 }, true);
setup();
- waitForAllCallsToFinish(1, () => {
+ return waitForAllCallsToFinish(1, () => {
expect(callbacks.success).not.toHaveBeenCalled();
expect(callbacks.error).not.toHaveBeenCalled();
expect(callbacks.notification).toHaveBeenCalled();
-
- done();
});
});
- it('should call the success callback when the interval header is -1', (done) => {
+ it('should call the success callback when the interval header is -1', () => {
mockServiceCall({ status: 200, headers: { 'poll-interval': -1 } });
- setup()
- .then(() => {
- expect(callbacks.success).toHaveBeenCalled();
- expect(callbacks.error).not.toHaveBeenCalled();
-
- done();
- })
- .catch(done.fail);
+ return setup().then(() => {
+ expect(callbacks.success).toHaveBeenCalled();
+ expect(callbacks.error).not.toHaveBeenCalled();
+ });
});
describe('for 2xx status code', () => {
successCodes.forEach((httpCode) => {
- it(`starts polling when http status is ${httpCode} and interval header is provided`, (done) => {
+ it(`starts polling when http status is ${httpCode} and interval header is provided`, () => {
mockServiceCall({ status: httpCode, headers: { 'poll-interval': 1 } });
const Polling = new Poll({
@@ -114,22 +104,20 @@ describe('Poll', () => {
Polling.makeRequest();
- waitForAllCallsToFinish(2, () => {
+ return waitForAllCallsToFinish(2, () => {
Polling.stop();
expect(service.fetch.mock.calls).toHaveLength(2);
expect(service.fetch).toHaveBeenCalledWith({ page: 1 });
expect(callbacks.success).toHaveBeenCalled();
expect(callbacks.error).not.toHaveBeenCalled();
-
- done();
});
});
});
});
describe('with delayed initial request', () => {
- it('delays the first request', async (done) => {
+ it('delays the first request', async () => {
mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } });
const Polling = new Poll({
@@ -144,21 +132,19 @@ describe('Poll', () => {
expect(Polling.timeoutID).toBeTruthy();
- waitForAllCallsToFinish(2, () => {
+ return waitForAllCallsToFinish(2, () => {
Polling.stop();
expect(service.fetch.mock.calls).toHaveLength(2);
expect(service.fetch).toHaveBeenCalledWith({ page: 1 });
expect(callbacks.success).toHaveBeenCalled();
expect(callbacks.error).not.toHaveBeenCalled();
-
- done();
});
});
});
describe('stop', () => {
- it('stops polling when method is called', (done) => {
+ it('stops polling when method is called', () => {
mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } });
const Polling = new Poll({
@@ -175,18 +161,16 @@ describe('Poll', () => {
Polling.makeRequest();
- waitForAllCallsToFinish(1, () => {
+ return waitForAllCallsToFinish(1, () => {
expect(service.fetch.mock.calls).toHaveLength(1);
expect(service.fetch).toHaveBeenCalledWith({ page: 1 });
expect(Polling.stop).toHaveBeenCalled();
-
- done();
});
});
});
describe('enable', () => {
- it('should enable polling upon a response', (done) => {
+ it('should enable polling upon a response', () => {
mockServiceCall({ status: 200 });
const Polling = new Poll({
resource: service,
@@ -200,19 +184,18 @@ describe('Poll', () => {
response: { status: 200, headers: { 'poll-interval': 1 } },
});
- waitForAllCallsToFinish(1, () => {
+ return waitForAllCallsToFinish(1, () => {
Polling.stop();
expect(service.fetch.mock.calls).toHaveLength(1);
expect(service.fetch).toHaveBeenCalledWith({ page: 4 });
expect(Polling.options.data).toEqual({ page: 4 });
- done();
});
});
});
describe('restart', () => {
- it('should restart polling when its called', (done) => {
+ it('should restart polling when its called', () => {
mockServiceCall({ status: 200, headers: { 'poll-interval': 1 } });
const Polling = new Poll({
@@ -238,7 +221,7 @@ describe('Poll', () => {
Polling.makeRequest();
- waitForAllCallsToFinish(2, () => {
+ return waitForAllCallsToFinish(2, () => {
Polling.stop();
expect(service.fetch.mock.calls).toHaveLength(2);
@@ -247,7 +230,6 @@ describe('Poll', () => {
expect(Polling.enable).toHaveBeenCalled();
expect(Polling.restart).toHaveBeenCalled();
expect(Polling.options.data).toEqual({ page: 4 });
- done();
});
});
});