-
-
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
add support to specify max level to shallow/mount #1042
Comments
That's not something that's possible with It will be possible after #1007; but it wouldn't be with a number level (which is brittle), it'd be by defining certain nodes as additional "leaves" that should not be dived into. |
thanks, take your word, though curious as to why it wouldn't be possible now with shallow. Agree taking a black list of nodes is more robust than taking a number. |
and is there a plan/open issue to do it, or should we create one and submit a PL |
|
thanks. is there an open issue? |
duplicate of #250 |
I know is useless for components inside the wrapper component, but for cases like this one may be useful for someone to shallow inside a shallow.
|
@lfelipequiros i'm relatively sure that wouldn't work; but you might want: shallow(
<WrapperComponent >
<Component {...props} />
</WrapperComponent>;
); ? |
@ljharb Why are you relatively sure ? maybe im missing something, but im seeing it working fine . . . Now that im giving it a closer look maybe is just parsing that shallow object to a unused param inside the wrapper component. I'll run a couple of test, if i can provide more context on this, i'll come back : ) |
An enzyme wrapper isn’t a node; React is probably converting it to a string implicitly. |
@lfelipequiros @ljharb
|
@HamidTanhaei that would fail if the children propType was defined as PropTypes.node. |
Just putting a link to docs for dive() https://enzymejs.github.io/enzyme/docs/api/ShallowWrapper/dive.html |
The same problem still exists, and since member @ljharb talk about an option to put a list of leaves nodes to avoid diving, I realized the best way for me was to:
For example, let's say I'm testing a Post page, then I mount it, and before doing this I mock components like: Comments, Similar Contents, Analytics, and keep the focus on Post information like the title, contents and interactions, etc. As to mock with jest, I use variable starting with import { Text as MockText } from 'react-native';
jest.mock('../../../../src/views/comments', () => {
return function Comments(props) {
return <MockText>Comments Here</MockText>;
};
}); There you escape the tons of components, you still benefit from |
shallow is one level deep vs mount is unlimited level deep, I wanted something in between - to be able to specify max level
can we add support to pass options.level to shallow/mount - e.g.
shallow(<MyCompoent />, {level: 2})
The text was updated successfully, but these errors were encountered: