forked from motiondivision/motion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.tsx
41 lines (38 loc) · 1.15 KB
/
jest.setup.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import "jest-dom/extend-expect"
// Get fireEvent from the native testing library
// because @testing-library/react one switches out mouseEnter and mouseLeave
import { fireEvent } from "@testing-library/dom"
import { render as testRender, act } from "@testing-library/react"
import * as React from "react"
export const click = (element: Element) =>
act(() => {
fireEvent.click(element)
})
export const mouseEnter = (element: Element) =>
act(() => {
fireEvent.mouseEnter(element)
})
export const mouseLeave = (element: Element) =>
act(() => {
fireEvent.mouseLeave(element)
})
export const mouseDown = (element: Element) =>
act(() => {
fireEvent.mouseDown(element)
})
export const mouseUp = (element: Element) =>
act(() => {
fireEvent.mouseUp(element)
})
export const render = (children: any) => {
const renderReturn = testRender(
<React.StrictMode>{children}</React.StrictMode>
)
return {
...renderReturn,
rerender: (children: any) =>
renderReturn.rerender(
<React.StrictMode>{children}</React.StrictMode>
),
}
}