Skip to content

Commit 3403ea8

Browse files
committed
Fixes tests for new context API and ensures currentContext is passed down recursion.
1 parent d01459d commit 3403ea8

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/__tests__/index.test.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -342,40 +342,41 @@ describe('reactTreeWalker', () => {
342342
it('supports new context API', () => {
343343
const { Provider, Consumer } = React.createContext()
344344

345-
class SomeInstance extends React.Component {
345+
class Foo extends React.Component {
346346
render() {
347-
return <div>{this.props.text}</div>
347+
return this.props.children
348348
}
349349
}
350350

351351
const tree = (
352352
<Provider
353353
value={{
354-
message: 'This is a provider message',
355-
handler: io => io,
354+
message: 'Message',
355+
identity: x => x,
356356
}}
357357
>
358358
<Consumer>
359-
{({ message, handler }) => (
359+
{({ message, identity }) => (
360360
<strong>
361-
<i>{`${message}: ${handler}`}</i>
361+
<i>{`${message}: ${identity('Hello world')}`}</i>
362362
</strong>
363363
)}
364364
</Consumer>
365-
Next
366-
<SomeInstance text="Dynamic text" />
365+
bar
366+
<Foo>foo</Foo>
367367
</Provider>
368368
)
369369

370370
const elements = []
371-
reactTreeWalker(tree, element => {
371+
return reactTreeWalker(tree, element => {
372372
elements.push(element)
373373
}).then(() => {
374-
expect(elements.pop()).toBe('Dynamic text')
375-
elements.pop() // Pop the div element
376-
elements.pop() // Pop the class instance
377-
expect(elements.pop()).toBe('Next')
378-
expect(elements.pop()).toBe('This is a provider message: io => io')
374+
expect(elements.pop()).toBe('foo')
375+
expect(elements.pop().type).toBe(Foo)
376+
expect(elements.pop()).toBe('bar')
377+
expect(elements.pop()).toBe('Message: Hello world')
378+
expect(elements.pop().type).toBe('i')
379+
expect(elements.pop().type).toBe('strong')
379380
})
380381
})
381382

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default function reactTreeWalker(
123123
const el = currentElement.props.children(
124124
currentElement.type.Provider._context._currentValue,
125125
)
126-
return recursive(el)
126+
return recursive(el, currentContext)
127127
}
128128
}
129129

0 commit comments

Comments
 (0)