@@ -62,7 +62,7 @@ describe('javascript-sdk', function() {
6262 requests . push ( req ) ;
6363 } ;
6464
65- sinon . spy ( LocalStoragePendingEventsDispatcher . prototype , 'sendPendingEvents' ) ;
65+ sinon . stub ( LocalStoragePendingEventsDispatcher . prototype , 'sendPendingEvents' ) ;
6666 } ) ;
6767
6868 afterEach ( function ( ) {
@@ -73,11 +73,39 @@ describe('javascript-sdk', function() {
7373 xhr . restore ( ) ;
7474 } ) ;
7575
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+
76105 it ( 'should invoke resendPendingEvents at most once' , function ( ) {
77106 var optlyInstance = optimizelyFactory . createInstance ( {
78107 datafile : { } ,
79108 errorHandler : fakeErrorHandler ,
80- eventDispatcher : fakeEventDispatcher ,
81109 logger : silentLogger ,
82110 } ) ;
83111 // Invalid datafile causes onReady Promise rejection - catch this error
@@ -88,7 +116,6 @@ describe('javascript-sdk', function() {
88116 optlyInstance = optimizelyFactory . createInstance ( {
89117 datafile : { } ,
90118 errorHandler : fakeErrorHandler ,
91- eventDispatcher : fakeEventDispatcher ,
92119 logger : silentLogger ,
93120 } ) ;
94121 optlyInstance . onReady ( ) . catch ( function ( ) { } ) ;
0 commit comments