Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating the mock #4327

Closed
6 tasks done
guptstagram opened this issue Oct 18, 2023 · 1 comment
Closed
6 tasks done

updating the mock #4327

guptstagram opened this issue Oct 18, 2023 · 1 comment

Comments

@guptstagram
Copy link

Describe the bug

Here's my react component

const LosingOrdersViewsBanner: FC = () => {
    const { subtab } = useIPPTabCount();

    console.log('A________', subtab);

    return (
        <InfoBanner
            icon={
                <InfoFilled
                    color={ThemeColors.yellowAction}
                    height={18}
                    width={18}
                />
            }
            message={
                subtab === SUBTABS_KEYS[1]
                    ? LOSING_BANNER_TEXTS.LOSING_VIEWS
                    : LOSING_BANNER_TEXTS.LOSING_ORDERS
            }
            severity="info"
        />
    );
};

Test File

describe('LosingOrdersViewsBanner', () => {
    it('should render the banner with the correct message for the orders subtab', () => {
        vi.mock('@store/actionCreators/IPPHooks/useIPPTabCount', () => ({
            default: vi.fn().mockReturnValue({ subtab: 'lorders' }),
        }));
        render(<LosingOrdersViewsBanner />);
        expect(
            screen.getByText(LOSING_BANNER_TEXTS.LOSING_ORDERS)
        ).toBeInTheDocument();
    });

    it('should render the banner with the correct message for the views subtab', async () => {
        vi.mock('@store/actionCreators/IPPHooks/useIPPTabCount', () => ({
            default: vi.fn().mockReturnValue({ subtab: 'lviews' }),
        }));
        render(<LosingOrdersViewsBanner />);
        expect(
            screen.getByText(LOSING_BANNER_TEXTS.LOSING_VIEWS)
        ).toBeInTheDocument();
    });
});

I am trying to get different values from a mock for two different test cases.

my component is using the value of subtab from hook useIPPTabCount const { subtab } = useIPPTabCount();

now for my first test case, I want the value of the subtab to be lorders and lviews for the second and maybe so on for further test cases but in vitest once I mock the module, it returns the same value for each test case.

Reproduction

NA

System Info

NA

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

This is a question, not an issue: #4328

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants