Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/WithFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (() => {
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/WithFlags.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
import toJson from 'enzyme-to-json'

const HBeta = () => <h4>for beta users</h4>;
const HStandard = () => <h4>for standard user</h4>;
Expand All @@ -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(<HeaderFeatureFlipped flags={{prevousFlag: true}} />);
expect(toJson(wrapper)).toMatchSnapshot();
});
});

describe('WithFlags', () => {
describe('flags as boolean', () => {
it('should return the component or element when flags is active (true)', () => {
Expand Down
26 changes: 26 additions & 0 deletions src/__tests__/__snapshots__/WithFlags.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Previous props Flags souhld be merged with current Flag 1`] = `
<togglerHOC
flags={
Object {
"prevousFlag": true,
}
}
>
<Consumer>
<HBeta
flags={
Object {
"betaOnly": true,
"prevousFlag": true,
}
}
>
<h4>
for beta users
</h4>
</HBeta>
</Consumer>
</togglerHOC>
`;