-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New React context API adds new tag types #1509
Comments
Tests are failing because of new node types within enzyme. Filed an issue here enzymejs/enzyme#1509
Here's the relevant build output from my test and the source that its covering |
any news on this? |
Nobody's put up a PR yet - so no news yet. |
Add support for react context element types, fixes #1509
Guys, publish a new version with this fix, please. No way for npm install from git monorepo sub dir drives me crazy: npm/npm#2974 |
@x3mka in the meanwhile, I've copied the The only difference from the file on master is the |
@diegohaz Thanks! |
If you're using jest I found that you can get decent results mocking out context with a utility function like so: // ensure you're resetting modules before each test
beforeEach(() => {
jest.resetModules();
});
const getComponentWithContext = context => {
// mock out the context you're using in the component
jest.doMock('./YourContext', () => {
return {
YourContext: {
Consumer: (props) => props.children(context)
}
}
});
// you need to re-require after calling jest.doMock.
// return the updated Component module that now includes the mocked context
return require('./Component');
};
// then use it like so...
it('should return stuff', () => {
const Component = getComponentWithContext({ data: 'here is some context data for test' });
const wrapper = mount(<Component />);
// now do your assertions
}); For a more detailed explanation I did a quick write up Unit testing components using React’s new Context API |
@ryandrewjohnson Thanks for the example! I'm curious as to what the the |
@icfantv , I think it would be Provider:(props)=>props.children |
Following up with @ryandrewjohnson's example, this can be done with shallow as well if you add .dive() at the end of the call. i.e. |
So issue was fixed, but not published on npm yet (for 1.5 months)? |
Please publish this, y'all. |
Still no update on this one? |
Not yet, things are in progress. Please be patient. |
This adds support for serializing React.Context in snapshots, see: enzymejs/enzyme#1513 also enzymejs/enzyme#1509
Any news on this topic? |
The following packages are now released: |
This is the general pattern we're going to see as we add withContext to components. In short, we have to export a wrapped version of the component as well as a basic version of it for testing. In our tests, we can pass in the hardcoded context object that the PropTypes expect and we're all good. // Worth pointing out that there's an enzyme problem whereby the new React Provider and Consumer nodes aren't recognized as legitimate nodes, so any tests that rely on them will fail. This should be addressed in the near future but for right now we can't do a lot about it. Source: - enzymejs/enzyme#1509 Since the LanguageSwitcher is part of the FederalBanner (and the LanguageSwitcher is wrapped in withContext), this means that we can't `mount` our FederalBanner component until enzyme is updated.
Enzyme throws an error whenever it's used to try and render a React Provider or Consumer. Source: - enzymejs/enzyme#1509 They've promised an update in the next week or so, but until then we can't `mount` any of our pages. Worth pointing out that these tests are pretty useless anyway.
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where is context used * updated Patternfly to newer version, the old one do not contains all required styles
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * updated Patternfly to newer version, the old one do not contains all required styles
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * updated Patternfly to newer version, the old one do not contains all required styles
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * updated Patternfly to newer version, the old one do not contains all required styles
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * updated Patternfly to newer version, the old one do not contains all required styles
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * updated Patternfly to newer version, the old one do not contains all required styles
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * deleted patch package (new included version do not need it)
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * deleted patch package (new included version does not need it)
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * deleted patch package (new included version does not need it)
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * deleted patch package (new included version does not need it)
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * deleted patch package (new included version does not need it)
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * deleted patch package (new included version does not need it)
* see enzymejs/enzyme#1509 for enzyme-adapter update, it throws an error in tests where context is used * deleted patch package (new included version does not need it)
The new API for context, publicly released just a few hours ago in the React 16.3 alpha, adds new tag types for the
Provider
andConsumer
components that are returned from thecreateContext
function.When updating my module to use the new API, I get an unknown node error from the
ReactSixteenAdapter.js
:I went in and took a stab at updating the adapter, and found that the Consumer prop has another new tag type, 12.
I added the following lines:
and tried adding cases for both of those in the module's switch statement, but none of the existing case handling options worked to get my tests passing again.
Environment
API
Version
Adapter
The text was updated successfully, but these errors were encountered: