Skip to content

How to use contains with function props? #204

Closed
@smacker

Description

contains method makes very simple testing complex component and don't care about markup. Something like this works great:

const MyComponent = () => (<div><Input /></div>)

it('should render input', () => {
    const wrapper = shallow(<MyComponent />);
    expect(wrapper.contains(<Input />)).to.equal(true);
});

But if I have function props, it doesn't work anymore:

class MyComponent extends React.Component {
    _onChange() {}

    render() {
        return <div><Input onChange={this._onChange.bind(this)} /></div>;
    }
}

it('should render input', () => {
    const wrapper = shallow(<MyComponent />);
    expect(wrapper.contains(<Input onChange={what_should_I_put_here?} />)).to.equal(true);
});

In some cases it is possible to make binding in constructor (then I can get function from instance and pass as prop), but not always.

Do you see any possible solution for this problem? (for example https://github.com/algolia/expect-jsx just skip all function props when compere jsx)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions