Skip to content

Commit 0d9f69e

Browse files
committed
Add tests for React.forwardRef
1 parent 7cd93e0 commit 0d9f69e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/__tests__/index.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,5 +467,26 @@ describe('reactTreeWalker', () => {
467467
expect(actual).toEqual(expected)
468468
})
469469
})
470+
471+
it('supports forwardRef', () => {
472+
class Foo extends ReactComponent {
473+
render() {
474+
return this.props.children
475+
}
476+
}
477+
478+
const Bar = React.forwardRef((props, ref) => <Foo ref={ref} {...props} />)
479+
480+
const tree = <Bar>foo</Bar>
481+
482+
const elements = []
483+
return reactTreeWalker(tree, element => {
484+
elements.push(element)
485+
}).then(() => {
486+
expect(elements.pop()).toBe('foo')
487+
expect(elements.pop().type).toBe(Foo)
488+
expect(elements.pop().type).toBe(Bar)
489+
})
490+
})
470491
})
471492
})

0 commit comments

Comments
 (0)