Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
How to update mock values state in Jest React Context

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();

  });
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda