Comments (7)
A bit more explanation:
A component that is wrapped with withDirection
will use direction context from the closest DirectionProvider. If DirectionProvider is not present anywhere in the tree, the withDirection HOC will use a LTR direction context by default. So technically DirectionProvider is not required.
In your tests, if you are testing something unrelated to direction you can choose to not provide a DirectionProvider. For example:
const wrapper = shallow(
<ForwardsLabel
onPress={onPress}
/>
).dive();
expect(wrapper.prop('foo')).to.equal('bar');
In this example I'm using Enzyme's dive
method to dive through the withDirection HOC.
from react-with-direction.
I'm confused, what do you mean "the fact that the tests don't have them"?
from react-with-direction.
If you're using withDirection
, then DirectionProvider
is required - so your tests also need to have them, otherwise they're not correct tests.
from react-with-direction.
I'll give you an example of the tests that fail:
it('Should remember state if its passed in', () => {
const wrapper = mount(
<MyComponent
onSubmit={mockSubmit}
/>
);
expect(wrapper.state('answer')).toBe('option2');
});
I understand that the Provider is required, but is the expectation in unit tests to write:
<DirectionProvider>
<ComponentToTest/>
</DirectionProvider>
?
Perhaps a utility function to provide context for tests would be helpful, e.g. for react-intl, a modified mount function can be used to provide context
function nodeWithIntlProp(node: ReactElement) {
return React.cloneElement(node, { intl });
}
export function mountWithIntl(node: ReactElement) {
return mount(nodeWithIntlProp(node), {
context: { intl },
childContextTypes: { intl: intlShape }
});
}
from react-with-direction.
Yes, that's the requirement in unit tests, to include the DirectionProvider explicitly.
from react-with-direction.
Ok, great. Thanks 👍
from react-with-direction.
Thanks @yzimet. That's very useful!
from react-with-direction.
Related Issues (11)
- Add support for React 16 HOT 2
- Expose ability to set classes on the DirectionProvider div HOT 1
- npm install - removes other modules HOT 3
- Impact babel-plugin-transform-replace-object-assign HOT 6
- Add styles for DirectionProvider div or span HOT 1
- React 17 HOT 12
- Legacy context usage prints warnings in React StrictMode HOT 3
- deepmerge is outdated HOT 1
- Typescript support HOT 1
- error in typescript project HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-with-direction.