Skip to content

Commit 74a3606

Browse files
authored
Merge pull request #76 from stoically/external-sinon
Expose and allow to pass in sinon instance
2 parents 31b315a + c6a5e8c commit 74a3606

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/api/events.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
*/
55

66
import {forEach} from 'lodash';
7-
import sinon from 'sinon';
87
import ChromeEvent from '../events/index';
98
import BaseCache from './cache';
109

1110
export default class EventsCache extends BaseCache {
1211

13-
constructor() {
12+
constructor(sinon) {
1413
super();
1514
this.events = Object.create(null);
1615
this.sandbox = sinon.sandbox.create();

src/api/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import {set, get, reduce, assign} from 'lodash';
7+
import sinon from 'sinon';
78
import Stubs from './stub';
89
import Events from './events';
910
import Props from './props';
@@ -29,11 +30,12 @@ export default class Api {
2930
/**
3031
* @param {Array<Object>} config
3132
*/
32-
constructor(config) {
33+
constructor(config, options = {}) {
34+
this.sinon = options.sinon ? options.sinon : sinon;
3335
this.NS_RULE = /^(.+)\.(.+)$/;
3436
this.config = config;
35-
this.stubs = new Stubs();
36-
this.events = new Events();
37+
this.stubs = new Stubs(this.sinon);
38+
this.events = new Events(this.sinon);
3739
this.props = new Props();
3840
this.manager = new Manager(this.stubs, this.events, this.props);
3941
}

src/api/stub.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* @overview Subs cache
44
*/
55

6-
import sinon from 'sinon';
76
import BaseCache from './cache';
87

98
export default class StubsCache extends BaseCache {
109

11-
constructor() {
10+
constructor(sinon) {
1211
super();
1312
this.stubs = Object.create(null);
13+
this.sinon = sinon;
1414
}
1515

1616
/**
@@ -42,7 +42,7 @@ export default class StubsCache extends BaseCache {
4242
* @returns {Function}
4343
*/
4444
create(key) {
45-
const stub = sinon.stub();
45+
const stub = this.sinon.stub();
4646
stub.flush = () => {
4747
this.deleteStub(key);
4848
};

0 commit comments

Comments
 (0)