I am trying to write the testing with my react-ts app. i am finding the setUserName does not exist error within it.
- need to confirm what should i test? ( i understand title should be with name )
- after mock api, how to set the value?
- how to test mock value existence?
any one please help me to understand/fix the issues?
my test code :
import React from "react";
import { render } from "@testing-library/react";
import App from "./App";
import apiForUserName from "../src/__mocks__/API";
describe("get username using promise", () => {
test("should load the users", async () => {
const userRes: any = await apiForUserName();
expect(userRes).toBeDefined();
const user = userRes.value.users[1];
expect(user.username).toEqual("Prakash");
const { setUserName, getByTitle } = render(<App />)
expect(setUserName).toHaveBeenCalledWith(user.username);
const titleElement = getByTitle(/Prakash/i);
expect(titleElement).toBeInTheDocument();
});
});