@@ -114,7 +114,7 @@ describe('lib/core/audience_evaluator', () => {
114114 } ) ;
115115
116116 afterEach ( ( ) => {
117- vi . restoreAllMocks ( ) ;
117+ vi . resetAllMocks ( ) ;
118118 } ) ;
119119
120120 describe ( 'APIs' , ( ) => {
@@ -217,10 +217,6 @@ describe('lib/core/audience_evaluator', () => {
217217 vi . clearAllMocks ( ) ;
218218 } ) ;
219219
220- afterEach ( ( ) => {
221- vi . resetAllMocks ( ) ;
222- } ) ;
223-
224220 afterAll ( ( ) => {
225221 vi . resetAllMocks ( ) ;
226222 } ) ;
@@ -283,30 +279,28 @@ describe('lib/core/audience_evaluator', () => {
283279 } ) ;
284280
285281 describe ( 'Audience evaluation logging' , ( ) => {
286- let mockCustomAttributeConditionEvaluator : ReturnType < typeof vi . fn > ;
287-
288282 const evaluateSpy = conditionTreeEvaluator . evaluate as unknown as MockInstance < typeof conditionTreeEvaluator . evaluate > ;
289283 const getEvaluatorSpy = customAttributeConditionEvaluator . getEvaluator as unknown as MockInstance < typeof customAttributeConditionEvaluator . getEvaluator > ;
290284
291285 beforeEach ( ( ) => {
292286 vi . clearAllMocks ( ) ;
293-
294- mockCustomAttributeConditionEvaluator = vi . fn ( ) ;
295- getEvaluatorSpy . mockReturnValue ( {
296- evaluate : mockCustomAttributeConditionEvaluator ,
297- } ) ;
298287 } ) ;
299288
300- afterEach ( ( ) => {
301- vi . restoreAllMocks ( ) ;
289+ afterAll ( ( ) => {
290+ vi . resetAllMocks ( ) ;
302291 } ) ;
303292
304293 it ( 'logs correctly when conditionTreeEvaluator.evaluate returns null' , ( ) => {
305294 evaluateSpy . mockImplementationOnce ( ( conditions : any , leafEvaluator ) => {
306295 return leafEvaluator ( conditions [ 1 ] ) ;
307296 } ) ;
308297
309- mockCustomAttributeConditionEvaluator . mockReturnValue ( null ) ;
298+ const mockCustomAttributeConditionEvaluator = vi . fn ( ) . mockReturnValue ( null ) ;
299+
300+ getEvaluatorSpy . mockReturnValue ( {
301+ evaluate : mockCustomAttributeConditionEvaluator ,
302+ } ) ;
303+
310304 const userAttributes = { device_model : 5.5 } ;
311305 const user = getMockUserContext ( userAttributes ) ;
312306
@@ -333,7 +327,11 @@ describe('lib/core/audience_evaluator', () => {
333327 return leafEvaluator ( conditions [ 1 ] ) ;
334328 } ) ;
335329
336- mockCustomAttributeConditionEvaluator . mockReturnValue ( true ) ;
330+ const mockCustomAttributeConditionEvaluator = vi . fn ( ) . mockReturnValue ( true ) ;
331+
332+ getEvaluatorSpy . mockReturnValue ( {
333+ evaluate : mockCustomAttributeConditionEvaluator ,
334+ } ) ;
337335
338336 const userAttributes = { device_model : 'iphone' } ;
339337 const user = getMockUserContext ( userAttributes ) ;
@@ -356,10 +354,16 @@ describe('lib/core/audience_evaluator', () => {
356354
357355 it ( 'logs correctly when conditionTreeEvaluator.evaluate returns false' , ( ) => {
358356 evaluateSpy . mockImplementationOnce ( ( conditions : any , leafEvaluator ) => {
357+ console . log ( 'evaluateSpy leafEvaluator called with conditions:' , conditions ) ;
359358 return leafEvaluator ( conditions [ 1 ] ) ;
360359 } ) ;
361360
362- mockCustomAttributeConditionEvaluator . mockReturnValue ( false ) ;
361+ const mockCustomAttributeConditionEvaluator = vi . fn ( ) . mockReturnValue ( false ) ;
362+
363+ getEvaluatorSpy . mockReturnValue ( {
364+ evaluate : mockCustomAttributeConditionEvaluator ,
365+ } ) ;
366+
363367
364368 const userAttributes = { device_model : 'android' } ;
365369 const user = getMockUserContext ( userAttributes ) ;
0 commit comments