Hi,
Could you please help me in the issue where i am stuck in the Mocking API section,
the test snippet:
describe(“ProductList”, () => {
it(“should render products list”, async () => {
render();
const items = await screen.findAllByRole("listitem");
expect(items.length).toBeGreaterThan(0);
});
and handlers file:
import { http, HttpResponse } from “msw”;
import { products } from “./data”;
export const handlers = [
http.get(“/categories”, () => {
return HttpResponse.json([
{ id: 1, name: “Electronics” },
{ id: 2, name: “Beauty” },
{ id: 3, name: “Gardening” },
]);
}),
http.get(“/products”, () => {
return HttpResponse.json(products);
}),
];
server file :
import { setupServer } from ‘msw/node’
import { handlers } from ‘./handlers’
export const server = setupServer(…handlers)
setup file:
import “@testing-library/jest-dom/vitest”;
import “cross-fetch/polyfill”;
import ResizeObserver from “resize-observer-polyfill”;
import { server } from “./mock/server”;
global.ResizeObserver = ResizeObserver;
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
and the error show in the terminal
TestingLibraryElementError: Unable to find role=“listitem”
Ignored nodes: comments, script, style
Ignored nodes: comments, script, style