Meu arquivo que contém o código abaixo retorna o aviso A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.
no terminal ao executar npm test
.
import { render, screen } from "@testing-library/react";
import React from "react";
import { RecoilRoot } from "recoil";
import useList from "../../state/hooks/useList";
import List from "./List";
jest.mock("../../state/hooks/useList")
describe("empty list", () => {
beforeEach(() => {
(useList as jest.Mock).mockReturnValue([])
})
test("should be rendered", () => {
render(
<RecoilRoot>
<List />
</RecoilRoot>
)
const items = screen.queryAllByRole("listitem")
expect(items).toHaveLength(0)
})
})
describe("not empty list", () => {
const participants = ["Ana", "Beatriz"]
beforeEach(() => {
(useList as jest.Mock).mockReturnValue(participants)
})
test("should be rendered", () => {
render(
<RecoilRoot>
<List />
</RecoilRoot>
)
const items = screen.queryAllByRole("listitem")
expect(items).toHaveLength(participants.length)
})
})
Print do caso de teste que falhou: