Socket
Book a DemoInstallSign in
Socket

expect-react-shallow

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect-react-shallow

JSX assertions with Chai-like API (based on unexpected-react)

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

expect-react-shallow

Build Status

A Chai’s expect like API wrapper for unexpected-react. It also accepts JSX instead of ShallowRenderer instance.

expect-react-shallow

Installation

npm install --save-dev expect-react-shallow

Usage

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/>);

	});

});

API

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.

Changelog

The changelog can be found on the Releases page.

Contributing

Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.

Author

  • Artem Sapegin

License

The MIT License, see the included License.md file.

Keywords

chai

FAQs

Package last updated on 31 May 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.