You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i am trying to use vi mock for the below code, but i am unable to alter the value of isProduction . It is always defaulting to the first case and i cannot mockresolvevalue as its not really a function.
`import { ThemeProvider } from '@mui/material/styles';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { IEnvironment } from 'src/interfaces';
import { lang } from 'src/utils';
import { theme } from 'src/utils/theme';
import { vi } from 'vitest';
`import { ThemeProvider } from '@mui/material/styles';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { IEnvironment } from 'src/interfaces';
import { lang } from 'src/utils';
import { theme } from 'src/utils/theme';
import { vi } from 'vitest';
This discussion was converted from issue #5674 on May 06, 2024 08:08.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Describe the bug
Hi Guys,
i am trying to use vi mock for the below code, but i am unable to alter the value of isProduction . It is always defaulting to the first case and i cannot mockresolvevalue as its not really a function.
`import { ThemeProvider } from '@mui/material/styles';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { IEnvironment } from 'src/interfaces';
import { lang } from 'src/utils';
import { theme } from 'src/utils/theme';
import { vi } from 'vitest';
import { About } from './About';
describe('About Component', () => {
beforeEach(() => {
vi.mock('src/hooks', () => ({
useGetProjectConfig: () => ({
data: {
gcf: {
apps: {
player: {
version: '1.0.0',
},
cod: {
version: '2.0.0',
},
components: {
version: '3.0.0',
},
},
},
},
}),
}));
});
afterEach(() => {
vi.clearAllMocks();
vi.resetModules();
});
it('renders about component with correct versions when isProduction is true', () => {
vi.mock('src/utils/environment', () => ({
isProduction: true,
SB_API_URL: '',
CCBE_API_URL: '',
}));
});
it('renders about component with correct versions when isProduction is false', () => {
vi.resetModules();
vi.mock('src/utils/environment', () => ({
isProduction: false,
SB_API_URL: '',
CCBE_API_URL: '',
}));
});
});
`
Reproduction
`import { ThemeProvider } from '@mui/material/styles';
import { render, screen } from '@testing-library/react';
import React from 'react';
import { IEnvironment } from 'src/interfaces';
import { lang } from 'src/utils';
import { theme } from 'src/utils/theme';
import { vi } from 'vitest';
import { About } from './About';
describe('About Component', () => {
beforeEach(() => {
vi.mock('src/hooks', () => ({
useGetProjectConfig: () => ({
data: {
gcf: {
apps: {
player: {
version: '1.0.0',
},
cod: {
version: '2.0.0',
},
components: {
version: '3.0.0',
},
},
},
},
}),
}));
});
afterEach(() => {
vi.clearAllMocks();
vi.resetModules();
});
it('renders about component with correct versions when isProduction is true', () => {
vi.mock('src/utils/environment', () => ({
isProduction: true,
SB_API_URL: '',
CCBE_API_URL: '',
}));
});
it('renders about component with correct versions when isProduction is false', () => {
vi.resetModules();
vi.mock('src/utils/environment', () => ({
isProduction: false,
SB_API_URL: '',
CCBE_API_URL: '',
}));
});
});
`
System Info
Used Package Manager
yarn
Validations
Beta Was this translation helpful? Give feedback.
All reactions