@@ -62,7 +62,7 @@ describe('javascript-sdk', function() {
62
62
requests . push ( req ) ;
63
63
} ;
64
64
65
- sinon . spy ( LocalStoragePendingEventsDispatcher . prototype , 'sendPendingEvents' ) ;
65
+ sinon . stub ( LocalStoragePendingEventsDispatcher . prototype , 'sendPendingEvents' ) ;
66
66
} ) ;
67
67
68
68
afterEach ( function ( ) {
@@ -73,11 +73,39 @@ describe('javascript-sdk', function() {
73
73
xhr . restore ( ) ;
74
74
} ) ;
75
75
76
+ describe ( 'when an eventDispatcher is not passed in' , function ( ) {
77
+ it ( 'should wrap the default eventDispatcher and invoke sendPendingEvents' , function ( ) {
78
+ var optlyInstance = optimizelyFactory . createInstance ( {
79
+ datafile : { } ,
80
+ errorHandler : fakeErrorHandler ,
81
+ logger : silentLogger ,
82
+ } ) ;
83
+ // Invalid datafile causes onReady Promise rejection - catch this error
84
+ optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
85
+
86
+ sinon . assert . calledOnce ( LocalStoragePendingEventsDispatcher . prototype . sendPendingEvents ) ;
87
+ } ) ;
88
+ } ) ;
89
+
90
+ describe ( 'when an eventDispatcher is passed in' , function ( ) {
91
+ it ( 'should NOT wrap the default eventDispatcher and invoke sendPendingEvents' , function ( ) {
92
+ var optlyInstance = optimizelyFactory . createInstance ( {
93
+ datafile : { } ,
94
+ errorHandler : fakeErrorHandler ,
95
+ eventDispatcher : fakeEventDispatcher ,
96
+ logger : silentLogger ,
97
+ } ) ;
98
+ // Invalid datafile causes onReady Promise rejection - catch this error
99
+ optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
100
+
101
+ sinon . assert . notCalled ( LocalStoragePendingEventsDispatcher . prototype . sendPendingEvents ) ;
102
+ } ) ;
103
+ } ) ;
104
+
76
105
it ( 'should invoke resendPendingEvents at most once' , function ( ) {
77
106
var optlyInstance = optimizelyFactory . createInstance ( {
78
107
datafile : { } ,
79
108
errorHandler : fakeErrorHandler ,
80
- eventDispatcher : fakeEventDispatcher ,
81
109
logger : silentLogger ,
82
110
} ) ;
83
111
// Invalid datafile causes onReady Promise rejection - catch this error
@@ -88,7 +116,6 @@ describe('javascript-sdk', function() {
88
116
optlyInstance = optimizelyFactory . createInstance ( {
89
117
datafile : { } ,
90
118
errorHandler : fakeErrorHandler ,
91
- eventDispatcher : fakeEventDispatcher ,
92
119
logger : silentLogger ,
93
120
} ) ;
94
121
optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
0 commit comments