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

Commit b92410e

Browse files
authored
Merge pull request #11 from DullReferenceException/pass-through-props
Pass props through to original component
2 parents e0a7178 + 614ac2c commit b92410e

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ coverage
77

88
# Build
99
dist
10+
11+
# Editor artifacts
12+
.idea

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export default (experimentName) =>
319319
* The wrapped component
320320
*/
321321
(Component) =>
322-
() => {
322+
(props) => {
323323
// Activate the experiment
324324
const isActive = activate(experimentName)
325325

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

330330
return <Component
331+
{...props}
331332
optimizely={{ experiment, variant, isActive }} />
332333
}

test/connect.js

+31
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,34 @@ test('connect: activated and experiment', (t) => {
124124
})
125125
t.is(frame.props.optimizely.isActive, true)
126126
})
127+
128+
test('connect: props pass-through', (t) => {
129+
global.window = mockOptimizelyWindow({
130+
allExperiments: {
131+
'A': {
132+
name: 'Experiment A',
133+
enabled: true
134+
}
135+
},
136+
variationMap: {
137+
'A': {
138+
'name': 'Variant A',
139+
'code': 'JSCODE'
140+
}
141+
},
142+
activeExperiments: ['A'],
143+
push: ([method, ...args]) => {
144+
if (method === 'activate') {
145+
window.optimizely.activeExperiments = window.optimizely.activeExperiments || []
146+
window.optimizely.activeExperiments.push(args[0])
147+
}
148+
}
149+
})
150+
151+
const renderer = createRenderer(
152+
connect('Experiment A')(TestComponent)
153+
)
154+
let frame = renderer.render({ other: 'props' })
155+
156+
t.is(frame.props.other, 'props')
157+
})

0 commit comments

Comments
 (0)