diff --git a/package.json b/package.json index 2238e5c..0ced291 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lectra/ld-react-feature-flags", - "version": "1.0.33", + "version": "1.0.34", "description": "Integrate Launch Darkly in your React app in a breeze", "contributors": [ { @@ -51,6 +51,7 @@ "cross-env": "^5.1.4", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.7.0", + "enzyme-to-json": "^3.4.3", "eslint": "^4.19.1", "eslint-config-standard": "^11.0.0", "eslint-config-standard-react": "^6.0.0", diff --git a/src/WithFlags.js b/src/WithFlags.js index 6438471..304e0f3 100644 --- a/src/WithFlags.js +++ b/src/WithFlags.js @@ -11,7 +11,9 @@ const WithFlags = key => (ComponentA, ComponentB = undefined) => {ldClient => { const flagValue = ldClient.variation(key, false); this.camelFlag = camelize(key); + const initialFlags = this.props.flags || {}; const featureProps = { + ...initialFlags, [this.camelFlag]: flagValue }; return (() => { diff --git a/src/__tests__/WithFlags.spec.js b/src/__tests__/WithFlags.spec.js index 0526633..627e43a 100644 --- a/src/__tests__/WithFlags.spec.js +++ b/src/__tests__/WithFlags.spec.js @@ -1,5 +1,6 @@ import React from 'react'; import { mount } from 'enzyme'; +import toJson from 'enzyme-to-json' const HBeta = () =>

for beta users

; const HStandard = () =>

for standard user

; @@ -23,6 +24,17 @@ const getComponentWithContext = context => { return require('../WithFlags').default; }; +describe('Previous props Flags', ()=>{ + it('souhld be merged with current Flag', ()=>{ + const WithFlags = getComponentWithContext({ + variation: jest.fn(() => true) + }); + const HeaderFeatureFlipped = WithFlags('beta-only')(HBeta); + const wrapper = mount(); + expect(toJson(wrapper)).toMatchSnapshot(); + }); +}); + describe('WithFlags', () => { describe('flags as boolean', () => { it('should return the component or element when flags is active (true)', () => { diff --git a/src/__tests__/__snapshots__/WithFlags.spec.js.snap b/src/__tests__/__snapshots__/WithFlags.spec.js.snap new file mode 100644 index 0000000..5a593d5 --- /dev/null +++ b/src/__tests__/__snapshots__/WithFlags.spec.js.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Previous props Flags souhld be merged with current Flag 1`] = ` + + + +

+ for beta users +

+
+
+
+`;