launchdarkly / jest-launchdarkly-mock

Easily unit test LaunchDarkly feature flagged components with jest
Apache License 2.0
25 stars 18 forks source link

Add ability to simulate a feature flag change event #53

Open Chase-Dickerson opened 1 year ago

Chase-Dickerson commented 1 year ago

Is your feature request related to a problem? Please describe. I have a scenario where a user of our UI gets redirected when a feature flag is changed -- for example, turning on our "maintenance" flag redirects the user to a maintenance screen and doesn't allow anyone access to the site until the maintenance flag is turned back off. I can test what the user sees when the flag is off, what they see when the flag is on, but I cannot test the transition the user experiences when that flag changes while they are on the website.

Describe the solution you'd like I would like to have a way to simulate a ldClient.on('change') event in a Jest test. We are using launchdarkly-react-client-sdk, so the desired event change would trigger a component re-render, which would be detectable by our test.

Describe alternatives you've considered Our team was previously using launchdarkly-js-client-sdk directly, and we were able to simulate the change in jest with that library by setting up a tricky workaround / callback behavior and manually updating the flags when they changed. With launchdarkly-react-client-sdk, we are only utilizing the "useFlags" hook now.

Thanks for considering some solution to this!

yusinto commented 1 year ago

Thank you for your submission. This has been filed internally as 194027 and we will discuss it.