1
1
import { render } from "@testing-library/react" ;
2
- import { act , renderHook } from "@testing-library/react-hooks" ;
3
2
4
- import { useVerticalDividerHeight , VerticalDivider } from "../VerticalDivider" ;
3
+ import { VerticalDivider } from "../VerticalDivider" ;
5
4
6
5
describe ( "VerticalDivider" , ( ) => {
7
6
it ( "should render as a div with the vertical divider class names" , ( ) => {
@@ -10,92 +9,6 @@ describe("VerticalDivider", () => {
10
9
11
10
expect ( divider . tagName ) . toBe ( "DIV" ) ;
12
11
expect ( divider . className ) . toBe ( "rmd-divider rmd-divider--vertical" ) ;
13
- } ) ;
14
-
15
- describe ( "useVerticalDividerHeight" , ( ) => {
16
- it ( "should throw an error if the maxHeight is less than 0" , ( ) => {
17
- // can't use renderHook for this since the error will be caught in the ErrorBoundary
18
- const Test = ( ) => {
19
- useVerticalDividerHeight ( - 1 ) ;
20
- return null ;
21
- } ;
22
-
23
- const consoleError = jest . spyOn ( console , "error" ) ;
24
- // hide React uncaught error message
25
- consoleError . mockImplementation ( ) ;
26
-
27
- expect ( ( ) => render ( < Test /> ) ) . toThrowError (
28
- "The `maxHeight` for a vertical divider height must be greater than 0"
29
- ) ;
30
- } ) ;
31
-
32
- it ( "should provide a ref callback and a height" , ( ) => {
33
- let { result } = renderHook ( ( ) => useVerticalDividerHeight ( 5 ) ) ;
34
- expect ( result . current ) . toEqual ( {
35
- ref : expect . any ( Function ) ,
36
- height : undefined ,
37
- } ) ;
38
-
39
- ( { result } = renderHook ( ( ) => useVerticalDividerHeight ( 0 ) ) ) ;
40
- expect ( result . current ) . toEqual ( {
41
- ref : expect . any ( Function ) ,
42
- height : undefined ,
43
- } ) ;
44
-
45
- ( { result } = renderHook ( ( ) => useVerticalDividerHeight ( 1 ) ) ) ;
46
- expect ( result . current ) . toEqual ( {
47
- ref : expect . any ( Function ) ,
48
- height : undefined ,
49
- } ) ;
50
- } ) ;
51
-
52
- it ( "should update the height value after the ref is called with an element" , ( ) => {
53
- const div = document . createElement ( "div" ) ;
54
- const parentDiv = document . createElement ( "div" ) ;
55
- parentDiv . appendChild ( div ) ;
56
- Object . defineProperty ( parentDiv , "offsetHeight" , { value : 100 } ) ;
57
-
58
- const { result } = renderHook ( ( ) => useVerticalDividerHeight ( 1 ) ) ;
59
- expect ( result . current . height ) . toBeUndefined ( ) ;
60
-
61
- act ( ( ) => result . current . ref ( div ) ) ;
62
- expect ( result . current . height ) . toBe ( 100 ) ;
63
- } ) ;
64
-
65
- it ( "should use the maxHeight as a multiplier if it is less than 1" , ( ) => {
66
- const div = document . createElement ( "div" ) ;
67
- const parentDiv = document . createElement ( "div" ) ;
68
- parentDiv . appendChild ( div ) ;
69
- Object . defineProperty ( parentDiv , "offsetHeight" , { value : 100 } ) ;
70
-
71
- const { result } = renderHook ( ( ) => useVerticalDividerHeight ( 0.6 ) ) ;
72
- expect ( result . current . height ) . toBeUndefined ( ) ;
73
-
74
- act ( ( ) => result . current . ref ( div ) ) ;
75
- expect ( result . current . height ) . toBe ( 60 ) ;
76
- } ) ;
77
-
78
- it ( "should use the maxHeight as a pixel value if it is greater than 1" , ( ) => {
79
- const div = document . createElement ( "div" ) ;
80
- const parentDiv = document . createElement ( "div" ) ;
81
- parentDiv . appendChild ( div ) ;
82
- Object . defineProperty ( parentDiv , "offsetHeight" , {
83
- value : 100 ,
84
- writable : true ,
85
- } ) ;
86
-
87
- const { result } = renderHook ( ( ) => useVerticalDividerHeight ( 80 ) ) ;
88
- expect ( result . current . height ) . toBeUndefined ( ) ;
89
-
90
- act ( ( ) => result . current . ref ( div ) ) ;
91
- expect ( result . current . height ) . toBe ( 80 ) ;
92
-
93
- Object . defineProperty ( parentDiv , "offsetHeight" , {
94
- value : 40 ,
95
- writable : true ,
96
- } ) ;
97
- act ( ( ) => result . current . ref ( div ) ) ;
98
- expect ( result . current . height ) . toBe ( 40 ) ;
99
- } ) ;
12
+ expect ( container ) . toMatchSnapshot ( ) ;
100
13
} ) ;
101
14
} ) ;
0 commit comments