
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
expect-react-shallow
Advanced tools
A Chai’s expect like API wrapper for unexpected-react. It also accepts JSX instead of ShallowRenderer instance.
npm install --save-dev expect-react-shallow
import React from 'react';
import { expect } from 'mocha';
import expectReactShallow from 'expect-react-shallow';
class TestComponent extends React.Component {
render() {
return <div className="foo">Hello React!</div>;
}
}
describe('TestComponent', () => {
it('works', () => {
// OK
expectReactShallow(<TestComponent/>)
.to.have.rendered(<div>Hello React!</div>);
// OK
expectReactShallow(<TestComponent/>)
.to.have.exactly.rendered(<div className="foo">Hello React!</div>);
// Error
expectReactShallow(<TestComponent/>)
.to.have.exactly.rendered(<div/>);
// OK
expectReactShallow(<TestComponent/>)
.to.contain(<div/>);
});
});
expectReactShallow(ReactComponent|JSX).to.have.rendered(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.have.rendered.with.all.children(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.have.exactly.rendered(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.contain(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.contain.exactly(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.contain.with.all.children(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.not.contain(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.not.contain.exactly(ReactComponent|JSX);
expectReactShallow(ReactComponent|JSX).to.not.contain.with.all.children(ReactComponent|JSX);
See details in unexpected-react docs.
The changelog can be found on the Releases page.
Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.
The MIT License, see the included License.md file.
FAQs
JSX assertions with Chai-like API (based on unexpected-react)
We found that expect-react-shallow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.