Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11 from DullReferenceException/pass-through-props
Browse files Browse the repository at this point in the history
Pass props through to original component
  • Loading branch information
onbjerg authored Mar 24, 2018
2 parents e0a7178 + 614ac2c commit b92410e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ coverage

# Build
dist

# Editor artifacts
.idea
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export default (experimentName) =>
* The wrapped component
*/
(Component) =>
() => {
(props) => {
// Activate the experiment
const isActive = activate(experimentName)

Expand All @@ -328,5 +328,6 @@ export default (experimentName) =>
const variant = getVariant(experimentName)

return <Component
{...props}
optimizely={{ experiment, variant, isActive }} />
}
31 changes: 31 additions & 0 deletions test/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,34 @@ test('connect: activated and experiment', (t) => {
})
t.is(frame.props.optimizely.isActive, true)
})

test('connect: props pass-through', (t) => {
global.window = mockOptimizelyWindow({
allExperiments: {
'A': {
name: 'Experiment A',
enabled: true
}
},
variationMap: {
'A': {
'name': 'Variant A',
'code': 'JSCODE'
}
},
activeExperiments: ['A'],
push: ([method, ...args]) => {
if (method === 'activate') {
window.optimizely.activeExperiments = window.optimizely.activeExperiments || []
window.optimizely.activeExperiments.push(args[0])
}
}
})

const renderer = createRenderer(
connect('Experiment A')(TestComponent)
)
let frame = renderer.render({ other: 'props' })

t.is(frame.props.other, 'props')
})

0 comments on commit b92410e

Please sign in to comment.