From 408b56bd948edc80b212cd8025bbbee921c69d6b Mon Sep 17 00:00:00 2001 From: Winnie Hellmann <winnie@gitlab.com> Date: Tue, 19 Dec 2017 13:20:06 +0100 Subject: [PATCH] Fix racing condition in Ajax call of merge_request_tabs_spec.js --- spec/javascripts/merge_request_tabs_spec.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/spec/javascripts/merge_request_tabs_spec.js b/spec/javascripts/merge_request_tabs_spec.js index 050f0ea9ebd..a6be474805b 100644 --- a/spec/javascripts/merge_request_tabs_spec.js +++ b/spec/javascripts/merge_request_tabs_spec.js @@ -290,15 +290,18 @@ import 'vendor/jquery.scrollTo'; $('body').removeAttr('data-page'); }); - it('requires an absolute pathname', function () { - spyOn($, 'ajax').and.callFake(function (options) { - expect(options.url).toEqual('/foo/bar/merge_requests/1/diffs.json'); + it('triggers Ajax request to JSON endpoint', function (done) { + const url = '/foo/bar/merge_requests/1/diffs'; + spyOn(this.class, 'ajaxGet').and.callFake((options) => { + expect(options.url).toEqual(`${url}.json`); + done(); }); - this.class.loadDiff('/foo/bar/merge_requests/1/diffs'); + this.class.loadDiff(url); }); - it('triggers scroll event when diff already loaded', function () { + it('triggers scroll event when diff already loaded', function (done) { + spyOn(this.class, 'ajaxGet').and.callFake(() => done.fail()); spyOn(document, 'dispatchEvent'); this.class.diffsLoaded = true; @@ -307,6 +310,7 @@ import 'vendor/jquery.scrollTo'; expect( document.dispatchEvent, ).toHaveBeenCalledWith(new CustomEvent('scroll')); + done(); }); describe('with inline diff', () => { -- 2.30.9