@@ -78,4 +78,34 @@ describe('cookieObservable', () => {
7878
7979 expect ( cookieChange ) . toBeUndefined ( )
8080 } )
81+
82+ it ( 'should not re-notify observers if the cookie has not changed since last notification when cookieStore is not supported' , ( ) => {
83+ Object . defineProperty ( window , 'cookieStore' , { get : ( ) => undefined , configurable : true } )
84+ const observable = createCookieObservable ( mockRumConfiguration ( ) , COOKIE_NAME )
85+
86+ const cookieChanges : Array < string | undefined > = [ ]
87+ subscription = observable . subscribe ( ( change ) => cookieChanges . push ( change ) )
88+
89+ setCookie ( COOKIE_NAME , 'foo' , COOKIE_DURATION )
90+ clock . tick ( WATCH_COOKIE_INTERVAL_DELAY ) // detects 'foo'
91+ clock . tick ( WATCH_COOKIE_INTERVAL_DELAY ) // no change since last notification
92+
93+ expect ( cookieChanges ) . toEqual ( [ 'foo' ] )
94+ } )
95+
96+ it ( 'should notify observers on consecutive cookie changes when cookieStore is not supported' , ( ) => {
97+ Object . defineProperty ( window , 'cookieStore' , { get : ( ) => undefined , configurable : true } )
98+ const observable = createCookieObservable ( mockRumConfiguration ( ) , COOKIE_NAME )
99+
100+ const cookieChanges : Array < string | undefined > = [ ]
101+ subscription = observable . subscribe ( ( change ) => cookieChanges . push ( change ) )
102+
103+ setCookie ( COOKIE_NAME , 'foo' , COOKIE_DURATION )
104+ clock . tick ( WATCH_COOKIE_INTERVAL_DELAY )
105+
106+ setCookie ( COOKIE_NAME , 'bar' , COOKIE_DURATION )
107+ clock . tick ( WATCH_COOKIE_INTERVAL_DELAY )
108+
109+ expect ( cookieChanges ) . toEqual ( [ 'foo' , 'bar' ] )
110+ } )
81111} )
0 commit comments