Gathering detailed insights and metrics for react-shallow-renderer
Gathering detailed insights and metrics for react-shallow-renderer
Gathering detailed insights and metrics for react-shallow-renderer
Gathering detailed insights and metrics for react-shallow-renderer
react-addons-test-utils
This package provides the React TestUtils add-on.
enzyme-shallow-equal
Adaptation of react-addons-shallow-compare, for independent usage
@storybook/react
Storybook React renderer
extend-shallow
Extend an object with the properties of additional objects. node.js/javascript util.
npm install react-shallow-renderer
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
31 Stars
298 Commits
12 Forks
9 Watching
18 Branches
4 Contributors
Updated on 18 Jun 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-4.5%
790,993
Compared to previous day
Last week
3.6%
4,214,202
Compared to previous week
Last month
8.7%
17,560,981
Compared to previous month
Last year
11.7%
193,144,242
Compared to previous year
2
1
31
react-shallow-renderer
When writing unit tests for React, shallow rendering can be helpful. Shallow rendering lets you render a component "one level deep" and assert facts about what its render method returns, without worrying about the behavior of child components, which are not instantiated or rendered. This does not require a DOM.
1# npm 2npm install react-shallow-renderer --save-dev 3 4# Yarn 5yarn add react-shallow-renderer --dev
For example, if you have the following component:
1function MyComponent() { 2 return ( 3 <div> 4 <span className="heading">Title</span> 5 <Subcomponent foo="bar" /> 6 </div> 7 ); 8}
Then you can assert:
1import ShallowRenderer from 'react-shallow-renderer';
2// in your test:
3const renderer = new ShallowRenderer();
4renderer.render(<MyComponent />);
5const result = renderer.getRenderOutput();
6expect(result.type).toBe('div');
7expect(result.props.children).toEqual([
8 <span className="heading">Title</span>,
9 <Subcomponent foo="bar" />,
10]);
Shallow testing currently has some limitations, namely not supporting refs.
Note:
We also recommend checking out Enzyme's Shallow Rendering API. It provides a nicer higher-level API over the same functionality.
shallowRenderer.render()
You can think of the shallowRenderer as a "place" to render the component you're testing, and from which you can extract the component's output.
shallowRenderer.render()
is similar to ReactDOM.render()
but it doesn't require DOM and only renders a single level deep. This means you can test components isolated from how their children are implemented.
shallowRenderer.getRenderOutput()
After shallowRenderer.render()
has been called, you can use shallowRenderer.getRenderOutput()
to get the shallowly rendered output.
You can then begin to assert facts about the output.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 6/18 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
30 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More