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

150
Views
How to test util function in React

I am trying to test the typescript until function that is used in React application.

  • I have application.status prop that is passed to the function

  • If application.status is open -- submitFunction should be called

  • There is IF condtion that will allow that call

  • I want to test does that function is called if application status is open

it('if open-status submitApp should be called', () => {
    render(<Underwriting />);
    
    const submitObj = {
      submitApp: submitApplication(
        appData,
        ContextMock,
        jest.fn(),
      ),
    };

    const submitSpy = jest.spyOn(submitObj, 'submitApp');

    // this is function that I want to test
    handleUnderwriting(sdkApplication, EnrollmentContextMock, jest.fn());
    expect(submitSpy).toHaveBeenCalled();
  });

This is handleUnderfwrting util function:

export const handleUnderwriting = (
  application: ObjData,
  enrollCtx: Ctx,
  send: PayloadSender<any>,
) => {

   // I want to mock appliction.status to has a value: OPEN 
   // and then check does submitApplication function is called 
  if (
    application.status === 'open' ||
    application.status === 'data_vendor_reflexive'
  ) {
    submitApplication(application, enrollCtx, () => send);
  }
}

This is the underwriting component where this handleUnderwriting function is called inside of useEffect


export const Underwriting: FC = () => {
  const { send } = useNavState();
  const enrollCtx = useContext(EnrollmentContext)!;
  const client = enrollCtx.client!;
  const application = enrollCtx.application!;
  const logger = getLogger();

  useEffect(() => {

    handleUnderwriting(application, enrollCtx, send);

  }, [application, application.status, client, enrollCtx, send, logger]);

  return (
    <div className="home-wrapper">
      <div className="py-6 "
        <TrustBox />
      </div>
    </div>
  );
};
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!