Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including expect-react-shallow with all npm packages installed. Try it out:

require("react/package.json"); // react is a peer dependency. require("react-dom/package.json"); // react-dom is a peer dependency. var expectReactShallow = require("expect-react-shallow")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

expect-react-shallow v1.2.1

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

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


License

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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free