@@ -10,9 +10,9 @@ expect.extend(toHaveNoViolations)
1010describe ( 'Button' , ( ) => {
1111 behavesAsComponent ( { Component : Button , options : { skipAs : true } } )
1212
13- it ( 'renders a <button>' , async ( ) => {
13+ it ( 'renders a <button>' , ( ) => {
1414 const container = render ( < Button > Default</ Button > )
15- const button = await container . findByRole ( 'button' )
15+ const button = container . getByRole ( 'button' )
1616 expect ( button . textContent ) . toEqual ( 'Default' )
1717 } )
1818
@@ -23,77 +23,82 @@ describe('Button', () => {
2323 cleanup ( )
2424 } )
2525
26- it ( 'preserves "onClick" prop' , async ( ) => {
26+ it ( 'preserves "onClick" prop' , ( ) => {
2727 const onClick = jest . fn ( )
2828 const container = render ( < Button onClick = { onClick } > Noop</ Button > )
29- const button = await container . findByRole ( 'button' )
29+ const button = container . getByRole ( 'button' )
3030 fireEvent . click ( button )
3131 expect ( onClick ) . toHaveBeenCalledTimes ( 1 )
3232 } )
3333
34- it ( 'respects width props' , async ( ) => {
34+ it ( 'respects width props' , ( ) => {
3535 const container = render ( < Button sx = { { width : 200 } } > Block</ Button > )
36- const button = await container . findByRole ( 'button' )
36+ const button = container . getByRole ( 'button' )
3737 expect ( button ) . toHaveStyleRule ( 'width' , '200px' )
3838 } )
3939
40- it ( 'respects the "disabled" prop' , async ( ) => {
40+ it ( 'respects the "disabled" prop' , ( ) => {
4141 const onClick = jest . fn ( )
4242 const container = render (
4343 < Button onClick = { onClick } disabled >
4444 Disabled
4545 </ Button >
4646 )
47- const button = await container . findByRole ( 'button' )
47+ const button = container . getByRole ( 'button' )
4848 expect ( button . hasAttribute ( 'disabled' ) ) . toEqual ( true )
4949 fireEvent . click ( button )
5050 expect ( onClick ) . toHaveBeenCalledTimes ( 0 )
5151 } )
5252
53- it ( 'respects the "variant" prop' , async ( ) => {
53+ it ( 'respects the "variant" prop' , ( ) => {
5454 const container = render ( < Button size = "small" > Smol</ Button > )
55- const button = await container . findByRole ( 'button' )
55+ const button = container . getByRole ( 'button' )
5656 expect ( button ) . toHaveStyleRule ( 'font-size' , '12px' )
5757 } )
5858
59- it ( 'respects the "fontSize" prop over the "variant" prop' , async ( ) => {
59+ it ( 'respects the "fontSize" prop over the "variant" prop' , ( ) => {
6060 const container = render (
6161 < Button size = "small" sx = { { fontSize : 20 } } >
6262 Big Smol
6363 </ Button >
6464 )
65- const button = await container . findByRole ( 'button' )
65+ const button = container . getByRole ( 'button' )
6666 expect ( button ) . toHaveStyleRule ( 'font-size' , '20px' )
6767 } )
6868
69- it ( 'styles primary button appropriately' , async ( ) => {
69+ it ( 'styles primary button appropriately' , ( ) => {
7070 const container = render ( < Button variant = "primary" > Primary</ Button > )
71- const button = await container . findByRole ( 'button' )
71+ const button = container . getByRole ( 'button' )
7272 expect ( button ) . toMatchSnapshot ( )
7373 } )
7474
75- it ( 'styles invisible button appropriately' , async ( ) => {
75+ it ( 'styles invisible button appropriately' , ( ) => {
7676 const container = render ( < Button variant = "invisible" > Invisible</ Button > )
77- const button = await container . findByRole ( 'button' )
77+ const button = container . getByRole ( 'button' )
7878 expect ( button ) . toMatchSnapshot ( )
7979 } )
8080
81- it ( 'styles danger button appropriately' , async ( ) => {
81+ it ( 'styles danger button appropriately' , ( ) => {
8282 const container = render ( < Button variant = "danger" > Danger</ Button > )
83- const button = await container . findByRole ( 'button' )
83+ const button = container . getByRole ( 'button' )
8484 expect ( button ) . toMatchSnapshot ( )
8585 } )
8686
87- it ( 'styles outline button appropriately' , async ( ) => {
87+ it ( 'styles outline button appropriately' , ( ) => {
8888 const container = render ( < Button variant = "outline" > Outline</ Button > )
89- const button = await container . findByRole ( 'button' )
89+ const button = container . getByRole ( 'button' )
9090 expect ( button ) . toMatchSnapshot ( )
9191 } )
9292
93- it ( 'styles icon only button to make it a square' , async ( ) => {
93+ it ( 'styles icon only button to make it a square' , ( ) => {
9494 const container = render ( < IconButton icon = { SearchIcon } aria-label = "Search button" /> )
95- const IconOnlyButton = await container . findByRole ( 'button' )
95+ const IconOnlyButton = container . getByRole ( 'button' )
9696 expect ( IconOnlyButton ) . toHaveStyleRule ( 'padding-right' , '8px' )
9797 expect ( IconOnlyButton ) . toMatchSnapshot ( )
9898 } )
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+ } )
99104} )
0 commit comments