@@ -59,7 +59,7 @@ describe('Feature Component', () => {
59
59
it ( 'should not show the feature component if the flag is not enabled' , ( ) => {
60
60
render (
61
61
< OpenFeatureProvider domain = { EVALUATION } >
62
- < FeatureFlag featureKey = { BOOL_FLAG_KEY } defaultValue = { false } >
62
+ < FeatureFlag flagKey = { BOOL_FLAG_KEY } defaultValue = { false } >
63
63
< ChildComponent />
64
64
</ FeatureFlag >
65
65
</ OpenFeatureProvider > ,
@@ -71,7 +71,7 @@ describe('Feature Component', () => {
71
71
it ( 'should fallback when provided' , ( ) => {
72
72
render (
73
73
< OpenFeatureProvider domain = { EVALUATION } >
74
- < FeatureFlag featureKey = { MISSING_FLAG_KEY } defaultValue = { false } fallback = { < div > Fallback</ div > } >
74
+ < FeatureFlag flagKey = { MISSING_FLAG_KEY } defaultValue = { false } fallback = { < div > Fallback</ div > } >
75
75
< ChildComponent />
76
76
</ FeatureFlag >
77
77
</ OpenFeatureProvider > ,
@@ -82,10 +82,10 @@ describe('Feature Component', () => {
82
82
screen . debug ( ) ;
83
83
} ) ;
84
84
85
- it ( 'should handle showing multivariate flags with bool match' , ( ) => {
85
+ it ( 'should handle showing multivariate flags with string match' , ( ) => {
86
86
render (
87
87
< OpenFeatureProvider domain = { EVALUATION } >
88
- < FeatureFlag featureKey = { STRING_FLAG_KEY } match = { 'greeting ' } defaultValue = { 'default' } >
88
+ < FeatureFlag flagKey = { STRING_FLAG_KEY } match = { 'hi ' } defaultValue = { 'default' } >
89
89
< ChildComponent />
90
90
</ FeatureFlag >
91
91
</ OpenFeatureProvider > ,
@@ -94,16 +94,45 @@ describe('Feature Component', () => {
94
94
expect ( screen . queryByText ( childText ) ) . toBeInTheDocument ( ) ;
95
95
} ) ;
96
96
97
- it ( 'should show the feature component if the flag is not enabled but negate is true' , ( ) => {
97
+ it ( 'should support custom predicate function' , ( ) => {
98
+ const customPredicate = ( expected : boolean | undefined , actual : { value : boolean } ) => {
99
+ // Custom logic: render if flag is NOT the expected value (negation)
100
+ return expected !== undefined ? actual . value !== expected : ! actual . value ;
101
+ } ;
102
+
103
+ render (
104
+ < OpenFeatureProvider domain = { EVALUATION } >
105
+ < FeatureFlag flagKey = { BOOL_FLAG_NEGATE_KEY } match = { true } predicate = { customPredicate } defaultValue = { false } >
106
+ < ChildComponent />
107
+ </ FeatureFlag >
108
+ </ OpenFeatureProvider > ,
109
+ ) ;
110
+
111
+ expect ( screen . queryByText ( childText ) ) . toBeInTheDocument ( ) ;
112
+ } ) ;
113
+
114
+ it ( 'should render children when no match is provided and flag is truthy' , ( ) => {
98
115
render (
99
116
< OpenFeatureProvider domain = { EVALUATION } >
100
- < FeatureFlag featureKey = { BOOL_FLAG_KEY } defaultValue = { false } >
117
+ < FeatureFlag flagKey = { BOOL_FLAG_KEY } defaultValue = { false } >
101
118
< ChildComponent />
102
119
</ FeatureFlag >
103
120
</ OpenFeatureProvider > ,
104
121
) ;
105
122
106
123
expect ( screen . queryByText ( childText ) ) . toBeInTheDocument ( ) ;
107
124
} ) ;
125
+
126
+ it ( 'should not render children when no match is provided and flag is falsy' , ( ) => {
127
+ render (
128
+ < OpenFeatureProvider domain = { EVALUATION } >
129
+ < FeatureFlag flagKey = { BOOL_FLAG_NEGATE_KEY } defaultValue = { false } >
130
+ < ChildComponent />
131
+ </ FeatureFlag >
132
+ </ OpenFeatureProvider > ,
133
+ ) ;
134
+
135
+ expect ( screen . queryByText ( childText ) ) . not . toBeInTheDocument ( ) ;
136
+ } ) ;
108
137
} ) ;
109
138
} ) ;
0 commit comments