Skip to content

Instantly share code, notes, and snippets.

@exaucae
Last active September 15, 2021 14:43
Show Gist options
  • Save exaucae/c2897f11596a94061c1059678615ba81 to your computer and use it in GitHub Desktop.
Save exaucae/c2897f11596a94061c1059678615ba81 to your computer and use it in GitHub Desktop.
React unit testing tricks
// Unit testing react-router 

// pay attention to write it at your test file top level
const mockedUsedNavigate = jest.fn();

jest.mock('react-router-dom', () => ({
   ...jest.requireActual('react-router-dom') as any,
  useNavigate: () => mockedUsedNavigate,
}));

// your describe/it/test blocks go down there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment