Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

62
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!

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.