I need guidance on how to test and change react context mock values with jest, What I have done is created context which has two properties inputs and setInputs with my test the initial test are passing with the mock state of the inputs, where I hit a wall is how to change the values of the valuesValidate objects from property valid from mock state false to become true and test that there is change. I am just starting whit jest tesing so I would Appreciate any comments and help. I want to simulate a typing event that will change the values in the mocked stated for the valiedated properties to become from false to true. This is my test
it("user types on input fields", () => {
const mockState = {
initial: {
email: "some@email.com",
password: "1234567asd",
secretQuestionA: "some question",
secretQuestionB: "some question",
},
valuesValidate: {
email: { valid: false, errorMessage: "" },
password: { valid: false, errorMessage: "" },
secretQuestionA: { valid: false, errorMessage: "" },
secretQuestionB: { valid: false, errorMessage: "" },
},
};
const setInputs = jest.fn();
const inputs: InputsInitiaState = mockState;
const storeValues: IAccountDetailsContextProps = {
inputs,
setInputs,
};
render(
<AccountDetalsContext.Provider value={storeValues}>
<AccountDetails />
</AccountDetalsContext.Provider>
);
const emailInput = screen.getByTestId("email");
const passwordInput = screen.getByTestId("password");
const securityQuestionAInput = screen.getByTestId("security-question-1");
const securityQuestionBInput = screen.getByTestId("security-question-2");
const button = screen.getByTestId("continue-button");
user.click(button);
expect(emailInput).toHaveValue("some@email.com");
expect(passwordInput).toHaveValue("1234567asd");
expect(securityQuestionAInput).toHaveValue("some question");
expect(securityQuestionBInput).toHaveValue("some question");
expect(button).toBeInTheDocument();
});