From 4254825f3cc6fdcf3ed9d6ee491d56523d89ef40 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 27 Jul 2017 08:44:56 -0700 Subject: [PATCH 1/3] Remove duplicate mocking Since this was newly introduced, let's only set it up when clock mocking is specifically requested to minimize breakage. We really need to deprecate the global spec helper someday. It's bad news. /cc @hansonw --- spec/spec-helper.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 2379cc650..6ac492995 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -64,7 +64,6 @@ beforeEach -> atom.project.setPaths([specProjectPath]) window.resetTimeouts() - spyOn(Date, 'now').andCallFake -> window.now spyOn(_._, "now").andCallFake -> window.now spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout @@ -180,7 +179,6 @@ jasmine.useRealClock = -> jasmine.unspy(window, 'setTimeout') jasmine.unspy(window, 'clearTimeout') jasmine.unspy(_._, 'now') - jasmine.unspy(Date, 'now') # The clock is halfway mocked now in a sad and terrible way... only setTimeout # and clearTimeout are included. This method will also include setInterval. We From 899e9d3f8aeb7e8633c98df76e33e52c66bc5cac Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 31 Jul 2017 09:50:31 -0600 Subject: [PATCH 2/3] Explicitly request to use mock clock to get Date.now mocking --- spec/pane-spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/pane-spec.js b/spec/pane-spec.js index c36abbf6a..f05da0e28 100644 --- a/spec/pane-spec.js +++ b/spec/pane-spec.js @@ -1350,6 +1350,7 @@ describe('Pane', () => { let editor1, pane, eventCount beforeEach(async () => { + jasmine.useMockClock() editor1 = await atom.workspace.open('sample.txt', {pending: true}) pane = atom.workspace.getActivePane() eventCount = 0 From f33bca4fd9178ae6b9a77473f8227e5601e8d936 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 31 Jul 2017 10:14:44 -0600 Subject: [PATCH 3/3] Try always mocking Date.now in our global spec helper --- spec/pane-spec.js | 1 - spec/spec-helper.coffee | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/pane-spec.js b/spec/pane-spec.js index f05da0e28..c36abbf6a 100644 --- a/spec/pane-spec.js +++ b/spec/pane-spec.js @@ -1350,7 +1350,6 @@ describe('Pane', () => { let editor1, pane, eventCount beforeEach(async () => { - jasmine.useMockClock() editor1 = await atom.workspace.open('sample.txt', {pending: true}) pane = atom.workspace.getActivePane() eventCount = 0 diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 6ac492995..eec8ce5fb 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -65,6 +65,7 @@ beforeEach -> window.resetTimeouts() spyOn(_._, "now").andCallFake -> window.now + spyOn(Date, 'now').andCallFake(-> window.now) spyOn(window, "setTimeout").andCallFake window.fakeSetTimeout spyOn(window, "clearTimeout").andCallFake window.fakeClearTimeout @@ -179,6 +180,7 @@ jasmine.useRealClock = -> jasmine.unspy(window, 'setTimeout') jasmine.unspy(window, 'clearTimeout') jasmine.unspy(_._, 'now') + jasmine.unspy(Date, 'now') # The clock is halfway mocked now in a sad and terrible way... only setTimeout # and clearTimeout are included. This method will also include setInterval. We @@ -186,8 +188,6 @@ jasmine.useRealClock = -> jasmine.useMockClock = -> spyOn(window, 'setInterval').andCallFake(fakeSetInterval) spyOn(window, 'clearInterval').andCallFake(fakeClearInterval) - spyOn(Date, 'now').andCallFake(-> window.now) - addCustomMatchers = (spec) -> spec.addMatchers