diff --git a/__mocks__/@reach/router.js b/__mocks__/@reach/router.js index 05669f237f4eb..0c403e888de4b 100644 --- a/__mocks__/@reach/router.js +++ b/__mocks__/@reach/router.js @@ -1,5 +1,4 @@ module.exports = { ...jest.requireActual('@gatsbyjs/reach-router'), useLocation: jest.fn(), - useNavigate: jest.fn(() => jest.fn()), }; diff --git a/__mocks__/gatsby.js b/__mocks__/gatsby.js index ab1bac4a06e41..e236ebe193417 100644 --- a/__mocks__/gatsby.js +++ b/__mocks__/gatsby.js @@ -1,10 +1,11 @@ /* eslint-disable no-unused-vars */ -const React = require("react"); +const React = require('react'); module.exports = { - ...jest.requireActual("gatsby"), + ...jest.requireActual('gatsby'), graphql: jest.fn(), + navigate: jest.fn(), Link: jest.fn().mockImplementation( // these props are invalid for an `a` tag ({ @@ -18,7 +19,7 @@ module.exports = { to, ...rest }) => - React.createElement("a", { + React.createElement('a', { ...rest, href: to, }) diff --git a/src/components/hooks/__tests__/usePlatform.test.js b/src/components/hooks/__tests__/usePlatform.test.js index b4d61ae248869..e9b76cc083794 100644 --- a/src/components/hooks/__tests__/usePlatform.test.js +++ b/src/components/hooks/__tests__/usePlatform.test.js @@ -2,9 +2,9 @@ /* eslint import/no-unresolved: ['error', { ignore: ['@reach'] }] */ import React from 'react'; -import {useLocation, useNavigate} from '@reach/router'; +import {useLocation} from '@reach/router'; import {act, renderHook} from '@testing-library/react-hooks'; -import {useStaticQuery} from 'gatsby'; +import {navigate, useStaticQuery} from 'gatsby'; import {PageContext} from '../../pageContext'; import {useLocalStorage} from '../useLocalStorage'; @@ -28,6 +28,10 @@ const PLATFORMS = [ jest.mock('../useLocalStorage'); describe('usePlatform', () => { + beforeEach(() => { + jest.resetAllMocks(); + }); + it('uses the default of javascript', () => { const wrapper = ({children}) => ( {children} @@ -99,9 +103,6 @@ describe('usePlatform', () => { pathname: '/platforms/ruby/', }); - const navigate = jest.fn(); - - useNavigate.mockImplementation(() => navigate); useStaticQuery.mockImplementation(() => ({ allPlatform: { nodes: PLATFORMS, @@ -132,9 +133,6 @@ describe('usePlatform', () => { pathname: '/platforms/ruby/', }); - const navigate = jest.fn(); - - useNavigate.mockImplementation(() => navigate); useStaticQuery.mockImplementation(() => ({ allPlatform: { nodes: PLATFORMS, @@ -182,9 +180,7 @@ describe('usePlatform', () => { pathname: '/', search: '?platform=javascript', }); - const navigate = jest.fn(); - useNavigate.mockImplementation(() => navigate); useStaticQuery.mockImplementation(() => ({ allPlatform: { nodes: PLATFORMS, diff --git a/src/components/hooks/usePlatform.tsx b/src/components/hooks/usePlatform.tsx index 7aa797ceca778..bde7e8ae86f6d 100644 --- a/src/components/hooks/usePlatform.tsx +++ b/src/components/hooks/usePlatform.tsx @@ -1,6 +1,6 @@ import {useContext, useState} from 'react'; -import {useLocation, useNavigate, WindowLocation} from '@reach/router'; -import {graphql, useStaticQuery} from 'gatsby'; +import {useLocation, WindowLocation} from '@reach/router'; +import {graphql, navigate, useStaticQuery} from 'gatsby'; import {parse} from 'query-string'; import {PageContext} from 'sentry-docs/components/pageContext'; @@ -243,7 +243,6 @@ export function usePlatform( defaultValue: string = DEFAULT_PLATFORM ): UsePlatform { const location = useLocation(); - const navigate = useNavigate(); const pageContext = useContext(PageContext); diff --git a/src/pages/platform-redirect.tsx b/src/pages/platform-redirect.tsx index 4c27b468592d5..d00770dfccc67 100644 --- a/src/pages/platform-redirect.tsx +++ b/src/pages/platform-redirect.tsx @@ -1,5 +1,6 @@ import React, {useEffect} from 'react'; -import {useLocation, useNavigate} from '@reach/router'; +import {useLocation} from '@reach/router'; +import {navigate} from 'gatsby'; import {PlatformIcon} from 'platformicons'; import {parse} from 'query-string'; @@ -45,7 +46,6 @@ export default function PlatformRedirect() { const platformList = usePlatformList(); const location = useLocation(); - const navigate = useNavigate(); const queryString = parse(location.search, {arrayFormat: 'none'}); const path = (queryString.next as string | null) || ''; @@ -61,7 +61,7 @@ export default function PlatformRedirect() { if (shouldRedirect) { navigate(`/platforms/${requestedPlatform}${path}`); } - }, [navigate, path, requestedPlatform, shouldRedirect]); + }, [path, requestedPlatform, shouldRedirect]); if (shouldRedirect) { return null;