@@ -244,6 +244,15 @@ describe('Scope', () => {
244244 intArray : { value : [ 1 , 2 , 3 ] , type : 'integer[]' , unit : 'ms' } ,
245245 } ) ;
246246 } ) ;
247+
248+ it ( 'notifies scope listeners once per call' , ( ) => {
249+ const scope = new Scope ( ) ;
250+ const listener = vi . fn ( ) ;
251+ scope . addScopeListener ( listener ) ;
252+ scope . setAttribute ( 'str' , 'b' ) ;
253+ scope . setAttribute ( 'int' , 1 ) ;
254+ expect ( listener ) . toHaveBeenCalledTimes ( 2 ) ;
255+ } ) ;
247256 } ) ;
248257
249258 describe ( 'setAttributes' , ( ) => {
@@ -299,6 +308,42 @@ describe('Scope', () => {
299308 intArray : { type : 'integer[]' , value : [ 1 , 2 , 3 ] , unit : 'ms' } ,
300309 } ) ;
301310 } ) ;
311+
312+ it ( 'notifies scope listeners once per call' , ( ) => {
313+ const scope = new Scope ( ) ;
314+ const listener = vi . fn ( ) ;
315+ scope . addScopeListener ( listener ) ;
316+ scope . setAttributes ( { str : 'b' , int : 1 } ) ;
317+ scope . setAttributes ( { bool : true } ) ;
318+ expect ( listener ) . toHaveBeenCalledTimes ( 2 ) ;
319+ } ) ;
320+ } ) ;
321+
322+ describe ( 'removeAttribute' , ( ) => {
323+ it ( 'removes an attribute' , ( ) => {
324+ const scope = new Scope ( ) ;
325+ scope . setAttribute ( 'str' , 'b' ) ;
326+ scope . setAttribute ( 'int' , 1 ) ;
327+ scope . removeAttribute ( 'str' ) ;
328+ expect ( scope [ '_attributes' ] ) . toEqual ( { int : { type : 'integer' , value : 1 } } ) ;
329+ } ) ;
330+
331+ it ( 'notifies scope listeners after deletion' , ( ) => {
332+ const scope = new Scope ( ) ;
333+ const listener = vi . fn ( ) ;
334+ scope . addScopeListener ( listener ) ;
335+ } ) ;
336+
337+ it ( 'does nothing if the attribute does not exist' , ( ) => {
338+ const scope = new Scope ( ) ;
339+ const listener = vi . fn ( ) ;
340+
341+ scope . addScopeListener ( listener ) ;
342+ scope . removeAttribute ( 'str' ) ;
343+
344+ expect ( scope [ '_attributes' ] ) . toEqual ( { } ) ;
345+ expect ( listener ) . not . toHaveBeenCalled ( ) ;
346+ } ) ;
302347 } ) ;
303348
304349 test ( 'setUser' , ( ) => {
0 commit comments