@@ -4051,22 +4051,30 @@ describe('AmplitudeClient', function () {
4051
4051
4052
4052
it ( 'should use sendBeacon when beacon transport is set' , function ( ) {
4053
4053
sandbox . stub ( navigator , 'sendBeacon' ) . returns ( true ) ;
4054
+ const callback = sandbox . spy ( ) ;
4055
+ const errCallback = sandbox . spy ( ) ;
4054
4056
4055
4057
amplitude . init ( apiKey , null , { transport : constants . TRANSPORT_BEACON } ) ;
4056
- amplitude . logEvent ( 'test event' ) ;
4058
+ amplitude . logEvent ( 'test event' , { } , callback , errCallback ) ;
4057
4059
4058
4060
assert . equal ( navigator . sendBeacon . callCount , 1 ) ;
4059
4061
assert . equal ( amplitude . _unsentEvents . length , 0 ) ;
4062
+ assert . isTrue ( callback . calledOnce ) ;
4063
+ assert . isFalse ( errCallback . calledOnce ) ;
4060
4064
} ) ;
4061
4065
4062
4066
it ( 'should not remove event from unsentEvents if beacon returns false' , function ( ) {
4063
4067
sandbox . stub ( navigator , 'sendBeacon' ) . returns ( false ) ;
4068
+ const callback = sandbox . spy ( ) ;
4069
+ const errCallback = sandbox . spy ( ) ;
4064
4070
4065
4071
amplitude . init ( apiKey , null , { transport : constants . TRANSPORT_BEACON } ) ;
4066
- amplitude . logEvent ( 'test event' ) ;
4072
+ amplitude . logEvent ( 'test event' , { } , callback , errCallback ) ;
4067
4073
4068
4074
assert . equal ( navigator . sendBeacon . callCount , 1 ) ;
4069
4075
assert . equal ( amplitude . _unsentEvents . length , 1 ) ;
4076
+ assert . isFalse ( callback . calledOnce ) ;
4077
+ assert . isTrue ( errCallback . calledOnce ) ;
4070
4078
} ) ;
4071
4079
} ) ;
4072
4080
} ) ;
0 commit comments