diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-03-23 18:57:03 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-03-23 18:57:03 +0300 |
commit | 14b077b7cb77fd336e75f41427fe4c6170f55a8a (patch) | |
tree | 1048bbd9d6c77e28c0d3e42a6900a677f678863f /spec/javascripts | |
parent | d576fd82333c79b3f056f26f79e85c0eceb5704b (diff) |
Adds stop function so we can stop polling anytime
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/lib/utils/poll_spec.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/poll_spec.js b/spec/javascripts/lib/utils/poll_spec.js index 05bc6bfd74b..c794a632417 100644 --- a/spec/javascripts/lib/utils/poll_spec.js +++ b/spec/javascripts/lib/utils/poll_spec.js @@ -124,4 +124,40 @@ describe('Poll', () => { Vue.http.interceptors = _.without(Vue.http.interceptors, pollInterceptor); }); + + describe('stop', () => { + it('stops polling when method is called', (done) => { + const pollInterceptor = (request, next) => { + next(request.respondWith(JSON.stringify([]), { status: 200, headers: { 'poll-interval': 2 } })); + }; + + Vue.http.interceptors.push(pollInterceptor); + + const service = new ServiceMock('endpoint'); + spyOn(service, 'fetch').and.callThrough(); + + const Polling = new Poll({ + resource: service, + method: 'fetch', + data: { page: 1 }, + successCallback: () => { + Polling.stop(); + }, + errorCallback: callbacks.error, + }); + + spyOn(Polling, 'stop').and.callThrough(); + + Polling.makeRequest(); + + setTimeout(() => { + expect(service.fetch.calls.count()).toEqual(1); + expect(service.fetch).toHaveBeenCalledWith({ page: 1 }); + expect(Polling.stop).toHaveBeenCalled(); + done(); + }, 100); + + Vue.http.interceptors = _.without(Vue.http.interceptors, pollInterceptor); + }); + }); }); |