@@ -42,12 +42,47 @@ describe('evaluate visibility expression', () => {
4242 expect ( console . warn ) . not . toHaveBeenCalled ( ) ;
4343 } ) ;
4444
45- test ( 'warns and falls back to default for invalid expression' , ( ) => {
45+ test ( 'warns and falls back to default for invalid expression with feature ' , ( ) => {
4646 const value = createVisibilityExpression ( [ 'get' , 'x' ] , { } ) ;
4747
4848 vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
4949
50- expect ( value . evaluate ( ) ) . toBe ( 'visible' ) ;
50+ expect ( value . evaluate ( {
51+ properties : { x : 'none' }
52+ } ) ) . toBe ( 'visible' ) ;
53+ expect ( console . warn ) . toHaveBeenCalledWith ( 'Expected value to be of type string, but found null instead.' ) ;
54+ } ) ;
55+
56+ test ( 'falls back to default for invalid expression with zoom' , ( ) => {
57+ const value = createVisibilityExpression ( [ 'case' , [ '==' , [ 'zoom' ] , 5 ] , 'none' , 'visible' ] , { } ) ;
58+
59+ vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
60+
61+ expect ( value . evaluate ( {
62+ zoom : 5
63+ } ) ) . toBe ( 'visible' ) ;
64+ expect ( console . warn ) . not . toHaveBeenCalled ( ) ;
65+ } ) ;
66+
67+ test ( 'warns and falls back to default for invalid expression with feature' , ( ) => {
68+ const value = createVisibilityExpression ( [ 'get' , 'x' ] , { } ) ;
69+
70+ vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
71+
72+ expect ( value . evaluate ( {
73+ properties : { x : 'none' }
74+ } ) ) . toBe ( 'visible' ) ;
75+ expect ( console . warn ) . toHaveBeenCalledWith ( 'Expected value to be of type string, but found null instead.' ) ;
76+ } ) ;
77+
78+ test ( 'warns and falls back to default for invalid expression with feature state' , ( ) => {
79+ const value = createVisibilityExpression ( [ 'feature-state' , 'x' ] , { } ) ;
80+
81+ vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
82+
83+ expect ( value . evaluate ( {
84+ x : 'none'
85+ } ) ) . toBe ( 'visible' ) ;
5186 expect ( console . warn ) . toHaveBeenCalledWith ( 'Expected value to be of type string, but found null instead.' ) ;
5287 } ) ;
5388
0 commit comments