Skip to content

Commit

Permalink
[Tests] add test for forwardRef + createRef
Browse files Browse the repository at this point in the history
Closes #1852
  • Loading branch information
ljharb committed Oct 4, 2018
1 parent 34828de commit ab7d20d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
createClass,
createContext,
createPortal,
createRef,
forwardRef,
Fragment,
lazy,
Expand Down Expand Up @@ -604,6 +605,29 @@ describeWithDOM('mount', () => {
expect(results).to.have.lengthOf(1);
expect(results.props()).to.eql({ foo: 'hello' });
});

it('actually passes the ref', () => {
class A extends React.PureComponent {
render() {
return <div>FOO</div>;
}
}

class B extends React.PureComponent {
render() {
const { forwardedRef } = this.props;
return <A ref={forwardedRef} />;
}
}

const BForwarded = forwardRef((props, ref) => (
<B {...props} forwardedRef={ref} />
));

const ref = createRef();
mount(<BForwarded ref={ref} />);
expect(ref.current).to.be.an.instanceOf(A);
});
});

describeIf(is('> 0.13'), 'stateless function components (SFCs)', () => {
Expand Down

0 comments on commit ab7d20d

Please sign in to comment.