lets assume that we need to mock setStatus(). So, in test file we will mock by using jest as follows.
const setStatus = jest.fn();
const renderUserProfile = (props = {}) => {
return render(
<UserProfile status={true} setStatus={setStatus} />
)
}
const userProps1 = Props = {
status: true,
setStatus
}
const userProps2 = Props = {
status: false,
setStatus
}
describe('Component UserProfile', () => {
it("user status with true", () => {
renderUserProfile(userProps1);
const buttonElement = screen.getByRole("button").toHaveContext("Online");
fireEvent.click(userProps1);
expect(setStatus).toHaveBeenCalled();
});
it("user status with false", () => {
renderUserProfile(userProps1);
const buttonElement = screen.getByRole("button").toHaveContext("Offline");
fireEvent.click(userProps2);
expect(setStatus).toHaveBeenCalled();
});
})