Skip to content

Commit 5afeca3

Browse files
committed
Add additional legacy context test
1 parent 810cff4 commit 5afeca3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/__tests__/suspense.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,56 @@ describe('renderPrepass', () => {
365365
expect(TestC).toHaveBeenCalledTimes(2)
366366
})
367367
})
368+
369+
it('correctly tracks legacy context values across subtress and suspenses', () => {
370+
let hasSuspended = false
371+
372+
class Provider extends Component {
373+
getChildContext() {
374+
return { value: this.props.value }
375+
}
376+
377+
render() {
378+
return this.props.children
379+
}
380+
}
381+
382+
Provider.childContextTypes = { value: null }
383+
384+
class TestA extends Component {
385+
render() {
386+
expect(this.context.value).toBe('a')
387+
return null
388+
}
389+
}
390+
391+
class TestB extends Component {
392+
render() {
393+
expect(this.context.value).toBe('b')
394+
if (!hasSuspended) {
395+
throw Promise.resolve().then(() => (hasSuspended = true))
396+
}
397+
398+
return null
399+
}
400+
}
401+
402+
TestA.contextTypes = { value: null }
403+
TestB.contextTypes = { value: null }
404+
405+
const Wrapper = () => (
406+
<Fragment>
407+
<Provider value="a">
408+
<TestA />
409+
</Provider>
410+
<Provider value="b">
411+
<TestB />
412+
</Provider>
413+
</Fragment>
414+
)
415+
416+
return renderPrepass(<Wrapper />).then(() => {
417+
expect(hasSuspended).toBe(true)
418+
})
419+
})
368420
})

0 commit comments

Comments
 (0)