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

220
Views
Test is failing as one of the array is modified in the main component

I'm trying to empty an array named Variables which is located inside alertdetails object in React as it is a fix for one of the bugs but by doing so the existing Test cases are failing in this case how do I re-write the test case so that it doesn't fail?

it('should open send template drawer when "send now" button is clicked and initiator form feature is turned on and there are variables', () => {
        wrapper.setProps({
            alertDetails: {
                ...props.alertDetails,
                variables: [{ id: 1, group: 'placeholder' }]
            }
        });
        refreshComponent('actions');

        const sendButton = actions.find(CreateAlertsSendButton);

        sendButton.prop('onSendNow')();

        const drawer = wrapper.find(SendTemplate);

        expect(drawer.prop('isOpen')).toBeTruthy();
    });

    it('should not open send template drawer when "send now" button is clicked and initiator form feature is turned off', () => {
        const sendButton = actions.find(CreateAlertsSendButton);

        sendButton.prop('onSendNow')();

        const drawer = wrapper.find(SendTemplate);

        expect(drawer.exists()).toBeFalsy();
    });
     it('should call sendAlert when send template drawer executes callback', () => {
        wrapper.setProps({
            alertDetails: {
                ...props.alertDetails,
                variables: [{ id: 1, group: 'placeholder' }]
            }
        });
        refreshComponent('actions');

        const sendButton = actions.find(CreateAlertsSendButton);

        sendButton.prop('onSendNow')();

        wrapper
            .find('SendTemplate')
            .props()
            .onSendNow({ placeholders: 'placeholders' });

        expect(props.setVariableValues).toHaveBeenCalledWith('placeholders');
        expect(props.sendAlert).toHaveBeenCalledWith(AlertSendType.SEND_ONE_STEP, { redirectUrl: '' });
    });

Sorry for the extended code, the above three cases fail if I empty the Variables array

Currently, this test case checks whether we have a placeholder in alertDetails.Variables array but I need to implement it in a way that it should check from alertDetails.alertMessage so that emptying variables array doesn't affect these cases. I'd appreciate any help thanks!

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!