-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Support ForwardRef type of work in TestRenderer #12392
Changes from 4 commits
5ddf6f4
b9d091c
8a25f8c
a8d6721
610df95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,7 @@ | |
"description": "React package for snapshot testing.", | ||
"main": "index.js", | ||
"repository": "facebook/react", | ||
"keywords": [ | ||
"react", | ||
"react-native", | ||
"react-testing" | ||
], | ||
"keywords": ["react", "react-native", "react-testing"], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/facebook/react/issues" | ||
|
@@ -17,16 +13,11 @@ | |
"dependencies": { | ||
"fbjs": "^0.8.16", | ||
"object-assign": "^4.1.1", | ||
"prop-types": "^15.6.0" | ||
"prop-types": "^15.6.0", | ||
"react-is": "^16.3.0-alpha.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this require updates to our release/build script to keep these deps in sync? Needs follow up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm i don't know, I was conflating workspaces and lerna, the latter of which handles the updates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These versions are bumped by our release script manually. It's fine. I'll add it to my list of follow up things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed via 610df95 |
||
}, | ||
"peerDependencies": { | ||
"react": "^16.0.0 || 16.3.0-alpha.2" | ||
}, | ||
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"index.js", | ||
"shallow.js", | ||
"cjs/" | ||
] | ||
"files": ["LICENSE", "README.md", "index.js", "shallow.js", "cjs/"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,28 @@ describe('ReactShallowRenderer', () => { | |
]); | ||
}); | ||
|
||
it('should handle ForwardRef', () => { | ||
const testRef = React.createRef(); | ||
const SomeComponent = React.forwardRef((props, ref) => { | ||
expect(ref).toEqual(testRef); | ||
return ( | ||
<div> | ||
<span className="child1" /> | ||
<span className="child2" /> | ||
</div> | ||
); | ||
}); | ||
|
||
const shallowRenderer = createRenderer(); | ||
const result = shallowRenderer.render(<SomeComponent ref={testRef} />); | ||
|
||
expect(result.type).toBe('div'); | ||
expect(result.props.children).toEqual([ | ||
<span className="child1" />, | ||
<span className="child2" />, | ||
]); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: it('should handle ForwardRef', () => {
const testRef = React.createRef();
const SomeComponent = React.forwardRef((props, ref) => {
expect(ref).toEqual(testRef);
return (
<div>
<span className="child1" />
<span className="child2" />
</div>
)
});
const shallowRenderer = createRenderer();
const result = shallowRenderer.render(<SomeComponent ref={testRef} />);
expect(result.type).toBe('div');
expect(result.props.children).toEqual([
<span className="child1" />,
<span className="child2" />,
]);
}); |
||
|
||
it('should enable shouldComponentUpdate to prevent a re-render', () => { | ||
let renderCounter = 0; | ||
class SimpleComponent extends React.Component { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible to have a null React element type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably not in practice but the ShallowRenderer tests do
<NullIdentifer>
which was how i was hitting this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. 👍