Property 'setUserName' does not exist - jest testing with testing-library

Viewed 69

I am trying to write the testing with my react-ts app. i am finding the setUserName does not exist error within it.

  1. need to confirm what should i test? ( i understand title should be with name )
  2. after mock api, how to set the value?
  3. 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();
  });
});

Live-Demo;

0 Answers
Related