@@ -9,40 +9,53 @@ const Sandbox = require("./sinon/sandbox");
9
9
const stub = require ( "./sinon/stub" ) ;
10
10
const promise = require ( "./sinon/promise" ) ;
11
11
12
- const apiMethods = {
13
- createSandbox : createSandbox ,
14
- assert : require ( "./sinon/assert" ) ,
15
- match : require ( "@sinonjs/samsam" ) . createMatcher ,
16
- restoreObject : require ( "./sinon/restore-object" ) ,
17
-
18
- expectation : require ( "./sinon/mock-expectation" ) ,
19
- defaultConfig : require ( "./sinon/util/core/default-config" ) ,
20
-
21
- // fake timers
22
- timers : fakeTimers . timers ,
23
-
24
- // fake XHR
25
- xhr : nise . fakeXhr . xhr ,
26
- FakeXMLHttpRequest : nise . fakeXhr . FakeXMLHttpRequest ,
27
-
28
- // fake server
29
- fakeServer : nise . fakeServer ,
30
- fakeServerWithClock : nise . fakeServerWithClock ,
31
- createFakeServer : nise . fakeServer . create . bind ( nise . fakeServer ) ,
32
- createFakeServerWithClock : nise . fakeServerWithClock . create . bind (
33
- nise . fakeServerWithClock ,
34
- ) ,
35
-
36
- addBehavior : function ( name , fn ) {
37
- behavior . addBehavior ( stub , name , fn ) ;
38
- } ,
39
-
40
- // fake promise
41
- promise : promise ,
42
- } ;
43
-
44
- const sandbox = new Sandbox ( ) ;
45
-
46
- const api = extend ( sandbox , apiMethods ) ;
12
+ /**
13
+ * @param {object } opts injection point to override the default XHR lib in testing
14
+ * @param {object } opts.sinonXhrLib
15
+ * @returns {object } a configured sandbox
16
+ */
17
+ function createApi ( { sinonXhrLib } ) {
18
+ const apiMethods = {
19
+ createSandbox : createSandbox ,
20
+ assert : require ( "./sinon/assert" ) ,
21
+ match : require ( "@sinonjs/samsam" ) . createMatcher ,
22
+ restoreObject : require ( "./sinon/restore-object" ) ,
23
+
24
+ expectation : require ( "./sinon/mock-expectation" ) ,
25
+ defaultConfig : require ( "./sinon/util/core/default-config" ) ,
26
+
27
+ // fake timers
28
+ timers : fakeTimers . timers ,
29
+
30
+ // fake XHR
31
+ xhr : sinonXhrLib . fakeXhr . xhr ,
32
+ FakeXMLHttpRequest : sinonXhrLib . fakeXhr . FakeXMLHttpRequest ,
33
+
34
+ // fake server
35
+ fakeServer : sinonXhrLib . fakeServer ,
36
+ fakeServerWithClock : sinonXhrLib . fakeServerWithClock ,
37
+ createFakeServer : sinonXhrLib . fakeServer . create . bind (
38
+ sinonXhrLib . fakeServer ,
39
+ ) ,
40
+ createFakeServerWithClock : sinonXhrLib . fakeServerWithClock . create . bind (
41
+ sinonXhrLib . fakeServerWithClock ,
42
+ ) ,
43
+
44
+ addBehavior : function ( name , fn ) {
45
+ behavior . addBehavior ( stub , name , fn ) ;
46
+ } ,
47
+
48
+ // fake promise
49
+ promise : promise ,
50
+ } ;
51
+
52
+ const sandbox = new Sandbox ( ) ;
53
+ return extend ( sandbox , apiMethods ) ;
54
+ }
55
+
56
+ const api = createApi ( { sinonXhrLib : nise } ) ;
47
57
48
58
module . exports = api ;
59
+
60
+ // solely exposed for easier testing
61
+ module . exports . createApi = createApi ;
0 commit comments