@@ -10,9 +10,9 @@ expect.extend(toHaveNoViolations)
10
10
describe ( 'Button' , ( ) => {
11
11
behavesAsComponent ( { Component : Button , options : { skipAs : true } } )
12
12
13
- it ( 'renders a <button>' , async ( ) => {
13
+ it ( 'renders a <button>' , ( ) => {
14
14
const container = render ( < Button > Default</ Button > )
15
- const button = await container . findByRole ( 'button' )
15
+ const button = container . getByRole ( 'button' )
16
16
expect ( button . textContent ) . toEqual ( 'Default' )
17
17
} )
18
18
@@ -23,77 +23,82 @@ describe('Button', () => {
23
23
cleanup ( )
24
24
} )
25
25
26
- it ( 'preserves "onClick" prop' , async ( ) => {
26
+ it ( 'preserves "onClick" prop' , ( ) => {
27
27
const onClick = jest . fn ( )
28
28
const container = render ( < Button onClick = { onClick } > Noop</ Button > )
29
- const button = await container . findByRole ( 'button' )
29
+ const button = container . getByRole ( 'button' )
30
30
fireEvent . click ( button )
31
31
expect ( onClick ) . toHaveBeenCalledTimes ( 1 )
32
32
} )
33
33
34
- it ( 'respects width props' , async ( ) => {
34
+ it ( 'respects width props' , ( ) => {
35
35
const container = render ( < Button sx = { { width : 200 } } > Block</ Button > )
36
- const button = await container . findByRole ( 'button' )
36
+ const button = container . getByRole ( 'button' )
37
37
expect ( button ) . toHaveStyleRule ( 'width' , '200px' )
38
38
} )
39
39
40
- it ( 'respects the "disabled" prop' , async ( ) => {
40
+ it ( 'respects the "disabled" prop' , ( ) => {
41
41
const onClick = jest . fn ( )
42
42
const container = render (
43
43
< Button onClick = { onClick } disabled >
44
44
Disabled
45
45
</ Button >
46
46
)
47
- const button = await container . findByRole ( 'button' )
47
+ const button = container . getByRole ( 'button' )
48
48
expect ( button . hasAttribute ( 'disabled' ) ) . toEqual ( true )
49
49
fireEvent . click ( button )
50
50
expect ( onClick ) . toHaveBeenCalledTimes ( 0 )
51
51
} )
52
52
53
- it ( 'respects the "variant" prop' , async ( ) => {
53
+ it ( 'respects the "variant" prop' , ( ) => {
54
54
const container = render ( < Button size = "small" > Smol</ Button > )
55
- const button = await container . findByRole ( 'button' )
55
+ const button = container . getByRole ( 'button' )
56
56
expect ( button ) . toHaveStyleRule ( 'font-size' , '12px' )
57
57
} )
58
58
59
- it ( 'respects the "fontSize" prop over the "variant" prop' , async ( ) => {
59
+ it ( 'respects the "fontSize" prop over the "variant" prop' , ( ) => {
60
60
const container = render (
61
61
< Button size = "small" sx = { { fontSize : 20 } } >
62
62
Big Smol
63
63
</ Button >
64
64
)
65
- const button = await container . findByRole ( 'button' )
65
+ const button = container . getByRole ( 'button' )
66
66
expect ( button ) . toHaveStyleRule ( 'font-size' , '20px' )
67
67
} )
68
68
69
- it ( 'styles primary button appropriately' , async ( ) => {
69
+ it ( 'styles primary button appropriately' , ( ) => {
70
70
const container = render ( < Button variant = "primary" > Primary</ Button > )
71
- const button = await container . findByRole ( 'button' )
71
+ const button = container . getByRole ( 'button' )
72
72
expect ( button ) . toMatchSnapshot ( )
73
73
} )
74
74
75
- it ( 'styles invisible button appropriately' , async ( ) => {
75
+ it ( 'styles invisible button appropriately' , ( ) => {
76
76
const container = render ( < Button variant = "invisible" > Invisible</ Button > )
77
- const button = await container . findByRole ( 'button' )
77
+ const button = container . getByRole ( 'button' )
78
78
expect ( button ) . toMatchSnapshot ( )
79
79
} )
80
80
81
- it ( 'styles danger button appropriately' , async ( ) => {
81
+ it ( 'styles danger button appropriately' , ( ) => {
82
82
const container = render ( < Button variant = "danger" > Danger</ Button > )
83
- const button = await container . findByRole ( 'button' )
83
+ const button = container . getByRole ( 'button' )
84
84
expect ( button ) . toMatchSnapshot ( )
85
85
} )
86
86
87
- it ( 'styles outline button appropriately' , async ( ) => {
87
+ it ( 'styles outline button appropriately' , ( ) => {
88
88
const container = render ( < Button variant = "outline" > Outline</ Button > )
89
- const button = await container . findByRole ( 'button' )
89
+ const button = container . getByRole ( 'button' )
90
90
expect ( button ) . toMatchSnapshot ( )
91
91
} )
92
92
93
- it ( 'styles icon only button to make it a square' , async ( ) => {
93
+ it ( 'styles icon only button to make it a square' , ( ) => {
94
94
const container = render ( < IconButton icon = { SearchIcon } aria-label = "Search button" /> )
95
- const IconOnlyButton = await container . findByRole ( 'button' )
95
+ const IconOnlyButton = container . getByRole ( 'button' )
96
96
expect ( IconOnlyButton ) . toHaveStyleRule ( 'padding-right' , '8px' )
97
97
expect ( IconOnlyButton ) . toMatchSnapshot ( )
98
98
} )
99
+ it ( 'makes sure icon button has an aria-label' , ( ) => {
100
+ const container = render ( < IconButton icon = { SearchIcon } aria-label = "Search button" /> )
101
+ const IconOnlyButton = container . getByLabelText ( 'Search button' )
102
+ expect ( IconOnlyButton ) . toBeTruthy ( )
103
+ } )
99
104
} )
0 commit comments