Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda