1
- import { shallow , mount } from 'enzyme'
1
+ import { shallow } from 'enzyme'
2
2
import * as React from 'react'
3
3
4
4
import Ref from 'src/components/Ref/Ref'
5
- import { CompositeClass , CompositeFunction , DOMClass , DOMFunction } from './fixtures'
6
-
7
- const testInnerRef = Component => {
8
- const innerRef = jest . fn ( )
9
- const node = mount (
10
- < Ref innerRef = { innerRef } >
11
- < Component />
12
- </ Ref > ,
13
- ) . getDOMNode ( )
14
-
15
- expect ( innerRef ) . toHaveBeenCalledTimes ( 1 )
16
- expect ( innerRef ) . toHaveBeenCalledWith ( node )
17
- }
5
+ import RefFindNode from 'src/components/Ref/RefFindNode'
6
+ import RefForward from 'src/components/Ref/RefForward'
7
+ import { CompositeClass , ForwardedRef } from './fixtures'
18
8
19
9
describe ( 'Ref' , ( ) => {
20
10
describe ( 'children' , ( ) => {
@@ -24,38 +14,27 @@ describe('Ref', () => {
24
14
25
15
expect ( component . contains ( child ) ) . toBeTruthy ( )
26
16
} )
27
- } )
28
-
29
- describe ( 'innerRef' , ( ) => {
30
- it ( 'returns node from a functional component with DOM node' , ( ) => {
31
- testInnerRef ( DOMFunction )
32
- } )
33
-
34
- it ( 'returns node from a functional component' , ( ) => {
35
- testInnerRef ( CompositeFunction )
36
- } )
37
17
38
- it ( 'returns node from a class component with DOM node' , ( ) => {
39
- testInnerRef ( DOMClass )
40
- } )
18
+ it ( 'renders RefFindNode when a component is passed' , ( ) => {
19
+ const innerRef = React . createRef ( )
20
+ const wrapper = shallow (
21
+ < Ref innerRef = { innerRef } >
22
+ < CompositeClass />
23
+ </ Ref > ,
24
+ )
41
25
42
- it ( 'returns node from a class component' , ( ) => {
43
- testInnerRef ( CompositeClass )
26
+ expect ( wrapper . is ( RefFindNode ) ) . toBe ( true )
44
27
} )
45
28
46
- it ( 'returns "null" after unmount ' , ( ) => {
47
- const innerRef = jest . fn ( )
48
- const wrapper = mount (
29
+ it ( 'renders RefForward when a component wrapper with forwardRef() is passed ' , ( ) => {
30
+ const innerRef = React . createRef ( )
31
+ const wrapper = shallow (
49
32
< Ref innerRef = { innerRef } >
50
- < CompositeClass />
33
+ < ForwardedRef />
51
34
</ Ref > ,
52
35
)
53
36
54
- innerRef . mockClear ( )
55
- wrapper . unmount ( )
56
-
57
- expect ( innerRef ) . toHaveBeenCalledTimes ( 1 )
58
- expect ( innerRef ) . toHaveBeenCalledWith ( null )
37
+ expect ( wrapper . is ( RefForward ) ) . toBe ( true )
59
38
} )
60
39
} )
61
40
} )
0 commit comments