Skip to content

Commit

Permalink
test: when correct call 'callbackFn'
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Monteiro <gabrielmonteiro1203@gmail.com>
Co-authored-by: Jessica Luiza Silva de Oliveira <jluiza409@gmail.com>
Co-authored-by: Marcella Sanderle <marcellasanderle@gmail.com>
  • Loading branch information
4 people committed Sep 20, 2024
1 parent 250db3a commit d5509be
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/app/__tests__/modalmetrica.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,26 @@ describe("ModalMetrica Component", () => {
expect(getByText("Formato inválido!")).toBeTruthy(); // Verifica se a mensagem de erro está visível
});
});

it("chama callbackFn com o valor correto ao pressionar Salvar", () => {
const mockCallbackFn = jest.fn(); // Cria uma função mock para o callback
const { getByTestId } = render(
<ModalMetrica
visible={true}
callbackFn={mockCallbackFn} // Passa a função mock
closeModal={() => {}}
callbackValor={() => {}}
message="Teste"
metrica={mockItem}
/>
);

const input = getByTestId("valorInput"); // Obtém o input pelo testID
fireEvent.changeText(input, "123"); // Define um valor válido
fireEvent.press(getByTestId("callbackBtn")); // Pressiona o botão Salvar

expect(mockCallbackFn).toHaveBeenCalledWith("123"); // Verifica se a função foi chamada com o valor correto
});
});
});

0 comments on commit d5509be

Please sign in to comment.