Skip to content

Commit

Permalink
chore: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Nov 4, 2021
1 parent f7ad5aa commit 4a07d6b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"bracketSpacing": true,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
Expand Down
7 changes: 7 additions & 0 deletions packages/accordion/tests/accordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import {
AccordionPanel,
} from "../src"

jest.mock("@chakra-ui/transition", () => ({
...jest.requireActual("@chakra-ui/transition"),
Collapse: jest.fn(({ in: inProp, children }: any) => (
<div hidden={!inProp}>{children}</div>
)),
}))

it("passes a11y test", async () => {
await testA11y(
<Accordion>
Expand Down
4 changes: 3 additions & 1 deletion packages/hooks/tests/use-clipboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { invoke, renderHook } from "@chakra-ui/test-utils"
import { useClipboard } from "../src"

jest.mock("copy-to-clipboard")

jest.useFakeTimers()
jest.spyOn(global, "setTimeout")

const text = "lorem ipsum"

Expand All @@ -24,5 +26,5 @@ test.each`
})

expect(copy).toBeCalledWith(text, {})
expect(setTimeout).toHaveBeenCalledWith(expect.anything(), expected)
expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), expected)
})
13 changes: 6 additions & 7 deletions packages/tooltip/tests/tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,30 @@ test("should not show on mouseover if isDisabled is true", async () => {
jest.useRealTimers()
})

test("should close on mouseleave if openDelay is set", async () => {
test.only("should close on mouseleave if openDelay is set", async () => {
jest.useFakeTimers()

render(<DummyComponent openDelay={500} />)

act(() => {
fireEvent.mouseOver(screen.getByText(buttonLabel))
jest.advanceTimersByTime(200)
})

jest.advanceTimersByTime(200)
expect(screen.queryByText(tooltipLabel)).not.toBeInTheDocument()

act(() => {
jest.advanceTimersByTime(500)
fireEvent.mouseLeave(screen.getByText(buttonLabel))
})

expect(screen.getByText(buttonLabel)).toBeInTheDocument()
expect(screen.getByRole("tooltip")).toBeInTheDocument()
expect(screen.queryByText(tooltipLabel)).toBeInTheDocument()

act(() => {
jest.advanceTimersByTime(1000)
fireEvent.mouseLeave(screen.getByText(buttonLabel))
jest.advanceTimersByTime(200)
})

await waitForElementToBeRemoved(() => screen.getByText(tooltipLabel))
await waitForElementToBeRemoved(() => screen.queryByText(tooltipLabel))

jest.useRealTimers()
})
Expand Down

0 comments on commit 4a07d6b

Please sign in to comment.