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
Mocking module react-router-dom returns undefined after I set environment to jsdom.
If the environment is set to node. Everything works fine. And this only happens to react-router-dom, mocking other module also works fine.
Reproduction
import { renderHook } from '@testing-library/react';
import reactRouter from 'react-router-dom';
import { describe, expect, it, vi } from 'vitest';
import { useRouterAuthorize } from '../use-router-authorize';
vi.mock('react-router-dom');
describe('useRouterAuthorize', () => {
it('should', async () => {
const useMatches = vi.mocked(reactRouter.useMatches); //reactRouter is undefined
useMatches.mockReturnValue([
{
id: '',
pathname: '',
params: {},
data: null,
handle: {
access: ['admin'],
},
},
]);
const { result } = renderHook(() => useRouterAuthorize(['admin']));
expect(result.current).toBeTruthy();
});
});
Describe the bug
Mocking module
react-router-dom
returnsundefined
after I set environment tojsdom
.If the environment is set to
node
. Everything works fine. And this only happens toreact-router-dom
, mocking other module also works fine.Reproduction
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: