From fe1740c26ba8295d751357fa8c0783e7abbe0c2d Mon Sep 17 00:00:00 2001 From: Aleksey Tsvetkov Date: Sun, 31 Jan 2016 13:16:11 +0300 Subject: [PATCH 1/2] https://github.com/acvetkov/sinon-chrome/issues/26 Fix chrome.flush for stubs with withArgs behavior --- src/chrome-api/index.js | 4 +++- src/factory/cache.js | 7 +++++++ src/factory/stubs.js | 1 + test/specs/chrome.test.js | 11 +++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/chrome-api/index.js b/src/chrome-api/index.js index 4218724..dcda37c 100644 --- a/src/chrome-api/index.js +++ b/src/chrome-api/index.js @@ -6,6 +6,7 @@ import generateApi from '../chrome/index'; import EventsFactory from '../factory/events'; import StubsFactory from '../factory/stubs'; import PropsFactory from '../factory/property'; +import Cache from '../factory/cache'; import CookiePlugin from '../plugins/cookies'; @@ -40,8 +41,9 @@ const ChromeManager = { * Reset mock data and behaviour */ flush: function () { - EventsFactory.flush(); + Cache.flush(); StubsFactory.flush(); + EventsFactory.flush(); PropsFactory.flush(); }, diff --git a/src/factory/cache.js b/src/factory/cache.js index 4225f15..7b429b0 100644 --- a/src/factory/cache.js +++ b/src/factory/cache.js @@ -31,5 +31,12 @@ export default { this.eventsCache[key] = EventsFactory.get(); } return this.eventsCache[key]; + }, + + /** + * Flush cached data + */ + flush: function () { + this.stubCache = {}; } }; diff --git a/src/factory/stubs.js b/src/factory/stubs.js index 7383f50..749a6eb 100644 --- a/src/factory/stubs.js +++ b/src/factory/stubs.js @@ -31,5 +31,6 @@ export default { stub.reset(); stub.resetBehavior(); }); + this.stubs = []; } }; diff --git a/test/specs/chrome.test.js b/test/specs/chrome.test.js index a246227..31f4e6c 100644 --- a/test/specs/chrome.test.js +++ b/test/specs/chrome.test.js @@ -104,6 +104,17 @@ describe('chrome', function () { assert.notOk(chrome.runtime.getURL()); }); + it('should reset withArgs methods behavior', function () { + chrome.runtime.getURL.withArgs('1').returns('http://domain1.com'); + chrome.runtime.getURL.withArgs('2').returns('http://domain2.com'); + chrome.runtime.getURL.withArgs('3').returns('http://domain3.com'); + assert.equal(chrome.runtime.getURL('1'), 'http://domain1.com'); + assert.equal(chrome.runtime.getURL('2'), 'http://domain2.com'); + assert.equal(chrome.runtime.getURL('3'), 'http://domain3.com'); + chrome.flush(); + assert.notOk(chrome.runtime.getURL()); + }); + it('should remove all listeners', function () { var spy = sinon.spy(); chrome.cookies.onChanged.addListener(spy); From e047e4ba872358dfa0ff101b1ca41acb8e9430f6 Mon Sep 17 00:00:00 2001 From: Aleksey Tsvetkov Date: Sun, 31 Jan 2016 13:22:05 +0300 Subject: [PATCH 2/2] https://github.com/acvetkov/sinon-chrome/issues/26 Bump version 1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf4f02b..2782df8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sinon-chrome", - "version": "1.1.0", + "version": "1.1.1", "description": "Mock of chrome extensions API for unit testing under nodejs", "homepage": "https://github.com/acvetkov/sinon-chrome", "author": {