Skip to content

Commit

Permalink
Merge pull request #27 from acvetkov/chrome-flush
Browse files Browse the repository at this point in the history
chrome.flush for withArgs stubs
  • Loading branch information
acvetkov committed Jan 31, 2016
2 parents 7aedca1 + e047e4b commit 24d2993
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 3 additions & 1 deletion src/chrome-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -40,8 +41,9 @@ const ChromeManager = {
* Reset mock data and behaviour
*/
flush: function () {
EventsFactory.flush();
Cache.flush();
StubsFactory.flush();
EventsFactory.flush();
PropsFactory.flush();
},

Expand Down
7 changes: 7 additions & 0 deletions src/factory/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@ export default {
this.eventsCache[key] = EventsFactory.get();
}
return this.eventsCache[key];
},

/**
* Flush cached data
*/
flush: function () {
this.stubCache = {};
}
};
1 change: 1 addition & 0 deletions src/factory/stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ export default {
stub.reset();
stub.resetBehavior();
});
this.stubs = [];
}
};
11 changes: 11 additions & 0 deletions test/specs/chrome.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 24d2993

Please sign in to comment.