https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
f

faint-holiday-73702

01/13/2023, 3:42 PM
Hello Team. I started recently to use Growthbook in the Front-End (react). Now I stumble upon a problem with a unit test for a certain component; it actually validates if a component is being displayed. Since I added the “IfFeatureEnabled” component the test fails and I would like to know if there is a way of mocking its behaviour or something like this? Any help would be appreciated
f

fresh-football-47124

01/13/2023, 3:47 PM
Hi Filipe, welcome. That’s an interesting question, @future-teacher-7046 do you have any thoughts? One thing you could do, though it’s not ideal, is set a new attribute called ‘isUnitTest’ or something, and add a rule to evaluate that feature to the condition it expects. In the code, you’d just have to make sure that attribute is set correctly when the unit tests run. You could do something similar with user agents and saved groups if getting the isUnit test state is hard in the code.
👍 1
f

future-teacher-7046

01/13/2023, 6:09 PM
You can force specific feature values in the SDK:
Copy code
growthbook.setForcedFeatures(new Map([['my-feature', true], ['other-feature', 'forced-value']]))
👍 1
b

brief-football-97996

03/28/2023, 3:54 PM
I see this as an option, will investigate
87 Views