Feature Flags
This service allows us to use feature flags(FFs) more easily in vanilla JS and React.
Check Feature Flags
By passing in a string of the feature flag name, we can use hasFeatureFlag to check if a feature flag is enabled.
LinkedToAccount.tsx
import React from 'react'
import { hasFeatureFlag } from '@rhapsody/feature-flags'
export const LinkedToAccount: React.FC<LinkedToAccountProps> = () => {
return (
<>
hasFeatureFlag('conversation_intelligence_linking_opportunities') && (
<p>Feature Enabled</P>
)
</>
)
}
Testing Feature Flags
We have provided setFeatureFlags and clearFeatureFlags. These functions should be used for testing purposes only.
LinkedToAccount.spec.tsx
import { setFeatureFlags, clearFeatureFlags } from './featuresService'
describe('featuresService', () => {
afterAll(() => {
clearFeatureFlags()
})
describe('LinkedToAccount', () => {
it('Feature text is not present when feature flag is disabled', () => {
setFeatureFlags({
conversation_intelligence_linking_opportunities: false,
})
render(withContextProviders(<LinkedToAccount />))
const featureText = screen.queryByText('Feature Enabled')
expect(featureText).not.toBeInTheDocument()
})
})
})
Get Feature Flags
We have provided getActiveFeatureFlags. This function is only for advanced use cases and should not be used for checking feature flags.