From 1dd86a7b9c7238df8c34b4878afa88c97bcc14ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lu=C3=ADs?= Date: Fri, 7 Sep 2018 02:43:02 +0100 Subject: Proxy RAF and RIC on beforeEachs --- spec/javascripts/diffs/store/actions_spec.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/spec/javascripts/diffs/store/actions_spec.js b/spec/javascripts/diffs/store/actions_spec.js index 8b52c9bffc7..b1d1efb69b9 100644 --- a/spec/javascripts/diffs/store/actions_spec.js +++ b/spec/javascripts/diffs/store/actions_spec.js @@ -14,6 +14,25 @@ import mockFile from '../mock_data/diff_file'; import mockDiscussion from '../mock_data/diff_discussions'; describe('DiffsStoreActions', () => { + const originalMethods = { + requestAnimationFrame: global.requestAnimationFrame, + requestIdleCallback: global.requestIdleCallback, + }; + + beforeEach(() => { + ['requestAnimationFrame', 'requestIdleCallback'].forEach(method => { + global[method] = cb => { + cb(); + }; + }); + }); + + afterEach(() => { + ['requestAnimationFrame', 'requestIdleCallback'].forEach(method => { + global[method] = originalMethods[method]; + }); + }); + describe('setBaseConfig', () => { it('should set given endpoint and project path', done => { const endpoint = '/diffs/set/endpoint'; @@ -157,11 +176,6 @@ describe('DiffsStoreActions', () => { describe('startRenderDiffsQueue', () => { it('should set all files to RENDER_FILE', done => { - const actualRAF = global.requestAnimationFrame; - global.requestAnimationFrame = cb => { - cb(); - }; - const state = { diffFiles: [ { @@ -187,8 +201,6 @@ describe('DiffsStoreActions', () => { actions .startRenderDiffsQueue({ state, commit: pseudoCommit }) .then(() => { - global.requestAnimationFrame = actualRAF; - expect(state.diffFiles[0].renderIt).toBeTruthy(); expect(state.diffFiles[1].renderIt).toBeTruthy(); -- cgit v1.2.1