@@ -140,16 +140,61 @@ describe('Scope', () => {
140140 expect ( scope [ '_extra' ] ) . toEqual ( { a : undefined } ) ;
141141 } ) ;
142142
143- test ( 'setTag' , ( ) => {
144- const scope = new Scope ( ) ;
145- scope . setTag ( 'a' , 'b' ) ;
146- expect ( scope [ '_tags' ] ) . toEqual ( { a : 'b' } ) ;
143+ describe ( 'setTag' , ( ) => {
144+ it ( 'sets a tag' , ( ) => {
145+ const scope = new Scope ( ) ;
146+ scope . setTag ( 'a' , 'b' ) ;
147+ expect ( scope [ '_tags' ] ) . toEqual ( { a : 'b' } ) ;
148+ } ) ;
149+
150+ it ( 'sets a tag with undefined' , ( ) => {
151+ const scope = new Scope ( ) ;
152+ scope . setTag ( 'a' , 'b' ) ;
153+ scope . setTag ( 'a' , undefined ) ;
154+ expect ( scope [ '_tags' ] ) . toEqual ( { a : undefined } ) ;
155+ } ) ;
156+
157+ it ( 'notifies scope listeners once per call' , ( ) => {
158+ const scope = new Scope ( ) ;
159+ const listener = vi . fn ( ) ;
160+
161+ scope . addScopeListener ( listener ) ;
162+ scope . setTag ( 'a' , 'b' ) ;
163+ scope . setTag ( 'a' , 'c' ) ;
164+
165+ expect ( listener ) . toHaveBeenCalledTimes ( 2 ) ;
166+ } ) ;
167+
168+ it ( 'discards non-primitive values' , ( ) => {
169+ const scope = new Scope ( ) ;
170+ // @ts -expect-error we want to test with a non-primitive value despite types not allowing it
171+ scope . setTag ( 'a' , { b : 'c' } ) ;
172+ expect ( scope [ '_tags' ] ) . toEqual ( { } ) ;
173+ } ) ;
147174 } ) ;
148175
149- test ( 'setTags' , ( ) => {
150- const scope = new Scope ( ) ;
151- scope . setTags ( { a : 'b' } ) ;
152- expect ( scope [ '_tags' ] ) . toEqual ( { a : 'b' } ) ;
176+ describe ( 'setTags' , ( ) => {
177+ it ( 'sets tags' , ( ) => {
178+ const scope = new Scope ( ) ;
179+ scope . setTags ( { a : 'b' } ) ;
180+ expect ( scope [ '_tags' ] ) . toEqual ( { a : 'b' } ) ;
181+ } ) ;
182+
183+ it ( 'notifies scope listeners once per call' , ( ) => {
184+ const scope = new Scope ( ) ;
185+ const listener = vi . fn ( ) ;
186+ scope . addScopeListener ( listener ) ;
187+ scope . setTags ( { a : 'b' , c : 'd' } ) ;
188+ scope . setTags ( { a : 'e' , f : 'g' } ) ;
189+ expect ( listener ) . toHaveBeenCalledTimes ( 2 ) ;
190+ } ) ;
191+
192+ it ( 'discards non-primitive values' , ( ) => {
193+ const scope = new Scope ( ) ;
194+ // @ts -expect-error we want to test with a non-primitive value despite types not allowing it
195+ scope . setTags ( { a : { b : 'c' } , b : [ 1 , 2 , 3 ] , c : new Map ( ) , d : ( ) => { } } ) ;
196+ expect ( scope [ '_tags' ] ) . toEqual ( { } ) ;
197+ } ) ;
153198 } ) ;
154199
155200 test ( 'setUser' , ( ) => {
0 commit comments