Skip to content

mocking different values for different test cases in a file #4328

Answered by mcous
guptstagram asked this question in Q&A
Discussion options

You must be logged in to vote

When using vi.mock, it's important to remember that all calls to vi.mock are "hoisted" to the top of the file. What you've written is:

import { describe, expect, it, vi } from 'vitest'
import { render } from '@testing-library/react'
import LosingOrdersViewsBanner from '../LosingOrdersViewsBanner.ts'

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' }),
        }));
        // ...
    });

    it('should render the banner with the correct message for the views subtab', a…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@elpddev
Comment options

@YauhenIhnatsyeu
Comment options

@YauhenIhnatsyeu
Comment options

@mcous
Comment options

@AstralBaby
Comment options

Answer selected by guptstagram
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants