Skip to content

Instantly share code, notes, and snippets.

@rotimi-best
Forked from danmakenoise/test.js
Created August 28, 2019 16:39
Show Gist options
  • Save rotimi-best/03ef4985bc2bc4c5dd384724f27cfca6 to your computer and use it in GitHub Desktop.
Save rotimi-best/03ef4985bc2bc4c5dd384724f27cfca6 to your computer and use it in GitHub Desktop.

Revisions

  1. @danmakenoise danmakenoise revised this gist Apr 19, 2018. No changes.
  2. @danmakenoise danmakenoise created this gist Apr 19, 2018.
    20 changes: 20 additions & 0 deletions test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    // Component.js
    const Component = props => (
    <MyContext.Consumer>
    {(context) => (
    <Foo
    bar={props.bar}
    baz={context.baz}
    />
    )}
    </MyContext.Consumer>
    );

    // Component.test.js
    const outer = shallow(<Component bar="bar" />);
    const Children = outer.props().children;
    const wrapper = shallow(<Children baz="baz" />);

    expect(wrapper.find(Foo)).toHaveLength(1);
    expect(wrapper.find(Foo)).props().bar).toBe('bar');
    expect(wrapper.find(Foo)).props().baz).toBe('baz');