Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!