/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React from 'react'; import {useLocalPathname} from '../useLocalPathname'; import {renderHook} from '@testing-library/react-hooks'; import {StaticRouter} from 'react-router-dom'; import {Context} from '@docusaurus/docusaurusContext'; import type {DocusaurusContext} from '@docusaurus/types'; describe('useLocalPathname', () => { const createUseLocalPathnameMock = (context: DocusaurusContext) => (location: string) => renderHook(() => useLocalPathname(), { wrapper: ({children}) => ( {children} ), }).result.current; it('works for baseUrl: /', () => { const mockUseLocalPathname = createUseLocalPathnameMock({ siteConfig: {baseUrl: '/'}, }); expect(mockUseLocalPathname('/foo')).toBe('/foo'); }); it('works for non-root baseUrl', () => { const mockUseLocalPathname = createUseLocalPathnameMock({ siteConfig: {baseUrl: '/base/'}, }); expect(mockUseLocalPathname('/base/foo')).toBe('/foo'); }); });