Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
ShallowRenderer does not work with Class.contextType #14442
Do you want to request a feature or report a bug?
What is the current behavior?
The shallow renderer from the 'react-test-renderer' package does not work with Class.contextType. The component always receives an empty object as the context.
What is the expected behavior?
The shallow renderer should forward the context provided to the render method to the rendered component's this.context.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Steps to reproduce
The test below can be used to reproduce the problem (Open on codesandbox.io). The first test reproduces the bug and the second test shows a workaround.
The problem seems to be located here. The function getMaskedContext() checks the properties declared on type.contextTypes and filters out the properties from the context provided to the shallow render unless the types.contextTypes is declared.
Yes Den søn. 3. feb. 2019, 18:57 skrev Alex Berman <email@example.com:…
Is this issue still being worked on @charBap <https://github.com/charBap>? If not id be glad to take it on! @gaearon <https://github.com/gaearon> — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#14442 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/As-519wKdzNgTDFhGpxUMPXeVllO_IwQks5vJyMegaJpZM4ZT9xF> .
Is this being worked on @Aberman12? If not I would love to look into it :)