Hello Team. I started recently to use Growthbook i...
# ask-questions
f
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
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
You can force specific feature values in the SDK:
Copy code
growthbook.setForcedFeatures(new Map([['my-feature', true], ['other-feature', 'forced-value']]))
👍 1
b
I see this as an option, will investigate
207 Views