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

124
Visualizações
How do I change a value on a single test after a module has been mocked?

I am mocking a component that is available from an npm package:

jest.mock('@paypal/react-paypal-js', () => {
  const reactPaypalJs = jest.requireActual('@paypal/react-paypal-js');
  return {
    ...reactPaypalJs,
    PayPalButtons: (props) => {
      return (
        <button
          type="button"
          onClick={() => {
            props.onApprove({ subscriptionID: '123' });
          }}
        >
          Confirm PayPal Payment
        </button>
      );
    },
  };
});

describe('Subscribe Page', () => {
  it('should expect a subscription ID of 123', async () => {
    render(<PaymentPage />);
  
    // Simulate filling out the paypal form using the mock and then submit it
    userEvent.click(screen.getByRole('button', { name: 'Confirm PayPal Payment' }));

    await waitFor(() => {
      expect(trackEventStub).toHaveBeenLastCalledWith({
        name: Events.PaymentSuccess,
        properties: {
          paymentPlatform: 'PayPal',
        },
      });
    });
  });
});

I want to change the value of what is being sent to prop.onApprove when the button gets clicked on a single test. How can I do that?

I would prefer not to have to redefine PayPalButtons for each test where I want to change the subscriptionID, but if that's necessary I'll do that. I just can't figure out how to change it for tests individually.

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