@@ -222,6 +222,48 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
222222 } ;
223223
224224 this . _resetForTests = function ( config , keepPersistence , instance ) {
225+ if ( typeof window !== 'undefined' ) {
226+ type TestWindow = Window & { mParticle ?: { _isTestEnv ?: boolean } } ;
227+ const sdkWindow = window as TestWindow ;
228+ if ( sdkWindow . mParticle ?. _isTestEnv && config ) {
229+ type TestFlags = {
230+ eventBatchingIntervalMillis ?: number | string ;
231+ astBackgroundEvents ?: string ;
232+ offlineStorage ?: string ;
233+ } ;
234+ const configWithFlags = config as { flags ?: TestFlags } ;
235+ const flags = ( configWithFlags . flags ??= { } ) ;
236+ if ( flags . eventBatchingIntervalMillis == null ) {
237+ flags . eventBatchingIntervalMillis = 0 ;
238+ }
239+ if ( flags . astBackgroundEvents == null ) {
240+ flags . astBackgroundEvents = 'False' ;
241+ }
242+ if ( flags . offlineStorage == null ) {
243+ flags . offlineStorage = '0' ;
244+ }
245+ window . onbeforeunload = null ;
246+ }
247+ }
248+
249+ if (
250+ instance ?. _Store ?. globalTimer &&
251+ instance . _Store . globalTimer > 0
252+ ) {
253+ clearTimeout ( instance . _Store . globalTimer ) ;
254+ instance . _Store . globalTimer = 0 ;
255+ }
256+
257+ if ( typeof window !== 'undefined' ) {
258+ type MParticleSDK = { _forwardingStatsTimer ?: number | null } ;
259+ const mParticleSDK = ( window as Window & { mParticle ?: MParticleSDK } ) . mParticle ;
260+ const forwardingStatsTimer = mParticleSDK ?. _forwardingStatsTimer ;
261+ if ( typeof forwardingStatsTimer === 'number' && mParticleSDK ) {
262+ clearInterval ( forwardingStatsTimer ) ;
263+ mParticleSDK . _forwardingStatsTimer = null ;
264+ }
265+ }
266+
225267 if ( instance . _Store ) {
226268 delete instance . _Store ;
227269 }
0 commit comments