Skip to content

Commit

Permalink
Add tests for React.forwardRef
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlangelaan committed Aug 10, 2018
1 parent 7cd93e0 commit 0d9f69e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,26 @@ describe('reactTreeWalker', () => {
expect(actual).toEqual(expected)
})
})

it('supports forwardRef', () => {
class Foo extends ReactComponent {
render() {
return this.props.children
}
}

const Bar = React.forwardRef((props, ref) => <Foo ref={ref} {...props} />)

const tree = <Bar>foo</Bar>

const elements = []
return reactTreeWalker(tree, element => {
elements.push(element)
}).then(() => {
expect(elements.pop()).toBe('foo')
expect(elements.pop().type).toBe(Foo)
expect(elements.pop().type).toBe(Bar)
})
})
})
})

0 comments on commit 0d9f69e

Please sign in to comment.