mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 00:27:21 +02:00
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
/**
|
|
* 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}) => (
|
|
<Context.Provider value={context}>
|
|
<StaticRouter location={location}>{children}</StaticRouter>
|
|
</Context.Provider>
|
|
),
|
|
}).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');
|
|
});
|
|
});
|