optimizely / react-sdk

React SDK for Optimizely Feature Experimentation and Optimizely Full Stack (legacy)
https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/javascript-react-sdk
Apache License 2.0
89 stars 35 forks source link

`isFeatureEnabled` Can't be mocked for E2E/Cypress tests. #188

Closed YamenSharaf closed 1 year ago

YamenSharaf commented 1 year ago

Problem

When I have a feature controlled by a feature flag, there's no way for me to force this feature's variations using Cypress tests. Ideally, I would like to test the flow when the feature is on and off.

For AB tests, we have setForcedVariation, which works to force a variation for testing, but no such thing for feature flags. I realize that if a feature flag has a feature test behind it, the feature test can be mocked instead, but that's not always the case.

This is something that should be addressed, IMO, as it seems a somewhat common case.

opti-jnguyen commented 1 year ago

Hi @YamenSharaf - have you tried using the setForcedDecision method to force a feature flag decision?

For more information, you can look at the documentation here: https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/forced-decision-methods-react

Let me know if that helps solve your issue.

YamenSharaf commented 1 year ago

@opti-jnguyen

As far as I know, setForcedDecision only works for forcing variations, whereas isFeatureEnabled returns a boolean.

I have confirmed this with the support team and this was the response I received

Unfortunately, forced bucketing methods can be only used for the feature tests/experiments. It's not yet supported for feature flags/rollouts. Also the mentioned [.setForcedDecision()](https://docs.developers.optimizely.com/full-stack/v4.0/docs/forced-decision-methods-react#set-forced-decision-method---setforceddecision:~:text=%3A%20string%3B%0A%7D-,Set%20Forced%20Decision%20Method%20%2D%20setForcedDecision(),-Version) apply only to a variation, not to a feature flag.

opti-jnguyen commented 1 year ago

Thanks @YamenSharaf - looked more into this and this may have to be a new feature request. Feel free to submit one here (https://feedback.optimizely.com/) as well as any suggestions you have on the implementation.