2
2
import { CSSProperties } from "react" ;
3
3
import { fireEvent , render } from "@testing-library/react" ;
4
4
5
- import { DropdownMenu } from "../DropdownMenu" ;
5
+ import { DropdownMenu , DropdownMenuProps } from "../DropdownMenu" ;
6
6
import { MenuItem } from "../MenuItem" ;
7
7
8
8
const getById = ( id : string ) => {
@@ -14,25 +14,23 @@ const getById = (id: string) => {
14
14
return el ;
15
15
} ;
16
16
17
- const PROPS = {
17
+ const PROPS : Omit < DropdownMenuProps , "items" > = {
18
18
id : "dropdown" ,
19
19
children : "Dropdown" ,
20
20
} ;
21
21
22
22
describe ( "DropdownMenu" , ( ) => {
23
23
it ( "should render correctly with a list of strings, numbers, ListItemProps, ReactElement, or a mixture of all" , ( ) => {
24
24
const items1 = [ "Item 1" , "Item 2" , "Item 3" ] ;
25
- const { container, rerender } = render (
26
- < DropdownMenu { ...PROPS } items = { items1 } />
27
- ) ;
28
- expect ( container ) . toMatchSnapshot ( ) ;
25
+ const { rerender } = render ( < DropdownMenu { ...PROPS } items = { items1 } /> ) ;
26
+ expect ( document . body ) . toMatchSnapshot ( ) ;
29
27
30
28
fireEvent . click ( getById ( "dropdown" ) ) ;
31
- expect ( container ) . toMatchSnapshot ( ) ;
29
+ expect ( document . body ) . toMatchSnapshot ( ) ;
32
30
33
31
const items2 = [ 0 , 1 , 2 , 3 , 4 ] ;
34
32
rerender ( < DropdownMenu { ...PROPS } items = { items2 } /> ) ;
35
- expect ( container ) . toMatchSnapshot ( ) ;
33
+ expect ( document . body ) . toMatchSnapshot ( ) ;
36
34
37
35
const items3 = [
38
36
{
@@ -42,7 +40,7 @@ describe("DropdownMenu", () => {
42
40
{ rightAddon : < i > icon</ i > , children : "Item 3" } ,
43
41
] ;
44
42
rerender ( < DropdownMenu { ...PROPS } items = { items3 } /> ) ;
45
- expect ( container ) . toMatchSnapshot ( ) ;
43
+ expect ( document . body ) . toMatchSnapshot ( ) ;
46
44
47
45
// Note: no key required
48
46
const items4 = [
@@ -54,7 +52,7 @@ describe("DropdownMenu", () => {
54
52
4 ,
55
53
] ;
56
54
rerender ( < DropdownMenu { ...PROPS } items = { items4 } /> ) ;
57
- expect ( container ) . toMatchSnapshot ( ) ;
55
+ expect ( document . body ) . toMatchSnapshot ( ) ;
58
56
} ) ;
59
57
60
58
it ( "should pass the menuStyle and menuClassName props to the menu correctly" , ( ) => {
0 commit comments