/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-plugin-content-docs/src/client/__tests__/docsVersion.test.tsx
47 строк
1 KB
Sébastien Lorber
refactor(test): use explicit Vitest imports, disable globals (#12019)
15 май 2026, 11:01
Не верифицирован
15 май 2026, 11:01
057ab88
Код
Авторство
О чём код?
/** * 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. */ // @vitest-environment jsdom import {describe, expect, it} from 'vitest'; import React from 'react'; import {renderHook} from '@testing-library/react'; import {useDocsVersion, DocsVersionProvider} from '../docsVersion'; import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs'; function testVersion(data?: Partial<PropVersionMetadata>): PropVersionMetadata { return { version: 'versionName', label: 'Version Label', className: 'version className', badge: true, banner: 'unreleased', docs: {}, docsSidebars: {}, isLast: false, pluginId: 'default', ...data, }; } describe('useDocsVersion', () => { it('throws if context provider is missing', () => { expect( () => renderHook(() => useDocsVersion()).result.current, ).toThrowErrorMatchingInlineSnapshot( `[ReactContextError: Hook useDocsVersion is called outside the <DocsVersionProvider>. ]`, ); }); it('reads value from context provider', () => { const version = testVersion(); const {result} = renderHook(() => useDocsVersion(), { wrapper: ({children}) => ( <DocsVersionProvider version={version}>{children}</DocsVersionProvider> ), }); expect(result.current).toBe(version); }); });