@@ -23,10 +23,20 @@ import testData from './tests/test_data';
23
23
import packageJSON from '../package.json' ;
24
24
import optimizelyFactory from './index.react_native' ;
25
25
import configValidator from './utils/config_validator' ;
26
- import defaultEventDispatcher from './plugins/event_dispatcher/index.browser' ;
27
26
import eventProcessorConfigValidator from './utils/event_processor_config_validator' ;
28
27
29
28
describe ( 'javascript-sdk/react-native' , function ( ) {
29
+ var clock ;
30
+ beforeEach ( function ( ) {
31
+ sinon . stub ( optimizelyFactory . eventDispatcher , 'dispatchEvent' ) ;
32
+ clock = sinon . useFakeTimers ( new Date ( ) ) ;
33
+ } ) ;
34
+
35
+ afterEach ( function ( ) {
36
+ optimizelyFactory . eventDispatcher . dispatchEvent . restore ( ) ;
37
+ clock . restore ( ) ;
38
+ } ) ;
39
+
30
40
describe ( 'APIs' , function ( ) {
31
41
it ( 'should expose logger, errorHandler, eventDispatcher and enums' , function ( ) {
32
42
assert . isDefined ( optimizelyFactory . logging ) ;
@@ -120,26 +130,15 @@ describe('javascript-sdk/react-native', function() {
120
130
} ) ;
121
131
122
132
describe ( 'when no event dispatcher passed to createInstance' , function ( ) {
123
- beforeEach ( function ( ) {
124
- sinon . stub ( defaultEventDispatcher , 'dispatchEvent' , function ( evt , cb ) {
125
- cb ( ) ;
126
- } ) ;
127
- } ) ;
128
-
129
- afterEach ( function ( ) {
130
- defaultEventDispatcher . dispatchEvent . restore ( ) ;
131
- } ) ;
132
-
133
133
it ( 'uses the default event dispatcher' , function ( ) {
134
134
var optlyInstance = optimizelyFactory . createInstance ( {
135
135
datafile : testData . getTestProjectConfig ( ) ,
136
136
errorHandler : fakeErrorHandler ,
137
137
logger : silentLogger ,
138
138
} ) ;
139
139
optlyInstance . activate ( 'testExperiment' , 'testUser' ) ;
140
- return optlyInstance . close ( ) . then ( function ( ) {
141
- sinon . assert . calledOnce ( defaultEventDispatcher . dispatchEvent ) ;
142
- } ) ;
140
+ clock . tick ( 30001 )
141
+ sinon . assert . calledOnce ( optimizelyFactory . eventDispatcher . dispatchEvent ) ;
143
142
} ) ;
144
143
} ) ;
145
144
@@ -185,7 +184,7 @@ describe('javascript-sdk/react-native', function() {
185
184
describe ( 'event processor configuration' , function ( ) {
186
185
var eventProcessorSpy ;
187
186
beforeEach ( function ( ) {
188
- eventProcessorSpy = sinon . stub ( eventProcessor , 'LogTierV1EventProcessor' ) . callThrough ( ) ;
187
+ eventProcessorSpy = sinon . spy ( eventProcessor , 'LogTierV1EventProcessor' ) ;
189
188
} ) ;
190
189
191
190
afterEach ( function ( ) {
0 commit comments