|
| 1 | +import _ from 'lodash' |
| 2 | +import React from 'react' |
| 3 | + |
| 4 | +import Ref from 'src/addons/Ref/Ref' |
| 5 | +import * as common from 'test/specs/commonTests' |
| 6 | +import { sandbox } from 'test/utils' |
| 7 | +import { CompositeClass, CompositeFunction, DOMClass, DOMFunction } from './fixtures' |
| 8 | + |
| 9 | +const nodeMount = (Component, innerRef) => ( |
| 10 | + mount( |
| 11 | + <Ref innerRef={innerRef}> |
| 12 | + <Component /> |
| 13 | + </Ref> |
| 14 | + ) |
| 15 | + .find('#node') |
| 16 | + .getDOMNode() |
| 17 | +) |
| 18 | + |
| 19 | +describe('Ref', () => { |
| 20 | + common.hasValidTypings(Ref, null, { |
| 21 | + requiredProps: { |
| 22 | + children: <div />, |
| 23 | + innerRef: _.noop, |
| 24 | + }, |
| 25 | + }) |
| 26 | + |
| 27 | + describe('innerRef', () => { |
| 28 | + it('returns node from a functional component with DOM node', () => { |
| 29 | + const innerRef = sandbox.spy() |
| 30 | + const node = nodeMount(DOMFunction, innerRef) |
| 31 | + |
| 32 | + innerRef.should.have.been.calledOnce() |
| 33 | + innerRef.should.have.been.calledWithMatch(node) |
| 34 | + }) |
| 35 | + |
| 36 | + it('returns node from a functional component', () => { |
| 37 | + const innerRef = sandbox.spy() |
| 38 | + const node = nodeMount(CompositeFunction, innerRef) |
| 39 | + |
| 40 | + innerRef.should.have.been.calledOnce() |
| 41 | + innerRef.should.have.been.calledWithMatch(node) |
| 42 | + }) |
| 43 | + |
| 44 | + it('returns node from a class component with DOM node', () => { |
| 45 | + const innerRef = sandbox.spy() |
| 46 | + const node = nodeMount(DOMClass, innerRef) |
| 47 | + |
| 48 | + innerRef.should.have.been.calledOnce() |
| 49 | + innerRef.should.have.been.calledWithMatch(node) |
| 50 | + }) |
| 51 | + |
| 52 | + it('returns node from a class component', () => { |
| 53 | + const innerRef = sandbox.spy() |
| 54 | + const node = nodeMount(CompositeClass, innerRef) |
| 55 | + |
| 56 | + innerRef.should.have.been.calledOnce() |
| 57 | + innerRef.should.have.been.calledWithMatch(node) |
| 58 | + }) |
| 59 | + }) |
| 60 | +}) |
0 commit comments