Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
// Default 5s timeout often fails on Windows :s,
// see https://github.com/facebook/docusaurus/pull/8259
testTimeout: 15000,
setupFiles: ['./jest/setup.js'],
setupFiles: ['./jest/setup.ts'],
testEnvironmentOptions: {
url: 'https://docusaurus.io/',
},
Expand Down
11 changes: 0 additions & 11 deletions jest/setup.js

This file was deleted.

8 changes: 8 additions & 0 deletions jest/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* 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.
*/

// Currently not used anymore, but kept for potential future setup needs
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@
"@prettier/plugin-xml": "^2.2.0",
"@swc/core": "^1.7.14",
"@swc/jest": "^0.2.39",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^30.0.0",
"@types/lodash": "^4.14.197",
"@types/node": "^18.16.19",
"@types/prompts": "^2.4.4",
"@types/react": "^19.2.10",
"@types/react-test-renderer": "^18.0.0",
"@types/semver": "^7.5.0",
"@types/shelljs": "^0.8.12",
"@typescript-eslint/eslint-plugin": "^5.62.0",
Expand Down Expand Up @@ -118,9 +119,8 @@
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.8.8",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-test-renderer": "^18.0.0",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"rimraf": "^3.0.2",
"sharp": "^0.32.3",
"strip-ansi": "^6.0.1",
Expand All @@ -129,6 +129,8 @@
"stylelint-config-standard": "^29.0.0",
"typescript": "~5.8.2"
},
"resolutions": {},
"resolutions": {
"**/pretty-format/react-is": "^19.2.4"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {useDocsSidebar, DocsSidebarProvider} from '../docsSidebar';
import type {PropSidebar} from '@docusaurus/plugin-content-docs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {StaticRouter} from 'react-router-dom';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {useDocsVersion, DocsVersionProvider} from '../docsVersion';
import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

exports[`Download icon Should render a snapshot that is good 1`] = `
<svg
height={24}
height="24"
viewBox="0 0 24 24"
width={24}
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path
Expand All @@ -20,9 +20,9 @@ exports[`Download icon Should render a snapshot that is good 1`] = `

exports[`Loading icon Should render a snapshot that is good 1`] = `
<svg
height={24}
height="24"
viewBox="0 0 24 24"
width={24}
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path
Expand All @@ -38,9 +38,9 @@ exports[`Loading icon Should render a snapshot that is good 1`] = `

exports[`Offline icon Should render a snapshot that is good 1`] = `
<svg
height={24}
height="24"
viewBox="0 0 24 24"
width={24}
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path
Expand All @@ -56,9 +56,9 @@ exports[`Offline icon Should render a snapshot that is good 1`] = `

exports[`Warning icon Should render a snapshot that is good 1`] = `
<svg
height={24}
height="24"
viewBox="0 0 24 24"
width={24}
width="24"
xmlns="http://www.w3.org/2000/svg"
>
<path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/**
* @jest-environment jsdom
*/

import React from 'react';
import renderer from 'react-test-renderer';
import {render} from '@testing-library/react';
import '@testing-library/jest-dom';
import Download from '../components/Icon/Download';
import Loading from '../components/Icon/Loading';
import Offline from '../components/Icon/Offline';
Expand All @@ -9,28 +14,28 @@ const snapshotTestDescription = 'Should render a snapshot that is good';

describe('Download icon', () => {
it(snapshotTestDescription, () => {
const download = renderer.create(<Download />).toJSON();
expect(download).toMatchSnapshot();
const {container} = render(<Download />);
expect(container.firstElementChild).toMatchSnapshot();
});
});

describe('Loading icon', () => {
it(snapshotTestDescription, () => {
const loading = renderer.create(<Loading />).toJSON();
expect(loading).toMatchSnapshot();
const {container} = render(<Loading />);
expect(container.firstElementChild).toMatchSnapshot();
});
});

describe('Offline icon', () => {
it(snapshotTestDescription, () => {
const offline = renderer.create(<Offline />).toJSON();
expect(offline).toMatchSnapshot();
const {container} = render(<Offline />);
expect(container.firstElementChild).toMatchSnapshot();
});
});

describe('Warning icon', () => {
it(snapshotTestDescription, () => {
const warning = renderer.create(<Warning />).toJSON();
expect(warning).toMatchSnapshot();
const {container} = render(<Warning />);
expect(container.firstElementChild).toMatchSnapshot();
});
});
1 change: 0 additions & 1 deletion packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@types/prismjs": "^1.26.0",
"@types/rtlcss": "^3.5.1",
"fs-extra": "^11.1.1",
"react-test-renderer": "^18.0.0",
"utility-types": "^3.10.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React, {type ReactNode} from 'react';
import renderer from 'react-test-renderer';
import {render} from '@testing-library/react';
import '@testing-library/jest-dom';
import {ScrollControllerProvider} from '@docusaurus/theme-common/internal';
import {StaticRouter} from 'react-router-dom';
import Tabs from '../index';
Expand All @@ -29,7 +34,7 @@ function TestProviders({
describe('Tabs', () => {
it('rejects bad Tabs child', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs>
<div>Naughty</div>
Expand All @@ -43,7 +48,7 @@ describe('Tabs', () => {
});
it('rejects bad Tabs defaultValue', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs defaultValue="bad">
<TabItem value="v1">Tab 1</TabItem>
Expand All @@ -57,7 +62,7 @@ describe('Tabs', () => {
});
it('rejects duplicate values', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs>
<TabItem value="v1">Tab 1</TabItem>
Expand All @@ -75,7 +80,7 @@ describe('Tabs', () => {
});
it('accepts valid Tabs config', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs>
<TabItem value="v1">Tab 1</TabItem>
Expand Down Expand Up @@ -129,7 +134,7 @@ describe('Tabs', () => {
it('accepts dynamic Tabs with number values', () => {
expect(() => {
const tabs = ['Apple', 'Banana', 'Carrot'];
renderer.create(
render(
<TestProviders>
<Tabs
values={tabs.map((t, idx) => ({label: t, value: idx}))}
Expand All @@ -146,7 +151,7 @@ describe('Tabs', () => {
});
it('rejects if querystring is true, but groupId falsy', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs queryString>
<TabItem value="val1">Val1</TabItem>
Expand All @@ -161,7 +166,7 @@ describe('Tabs', () => {

it('accept querystring=true when groupId is defined', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs queryString groupId="my-group-id">
<TabItem value="val1">Val1</TabItem>
Expand All @@ -174,7 +179,7 @@ describe('Tabs', () => {

it('accept querystring as string, but groupId falsy', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs queryString="qsKey">
<TabItem value="val1">Val1</TabItem>
Expand All @@ -187,7 +192,7 @@ describe('Tabs', () => {

it('accepts a single TabItem', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs>
<TabItem value="val1">Val1</TabItem>
Expand All @@ -199,7 +204,7 @@ describe('Tabs', () => {

it('allows a tab to be falsy', () => {
expect(() => {
renderer.create(
render(
<TestProviders>
<Tabs>
<TabItem value="val1">Val1</TabItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

import {renderHook} from '@testing-library/react-hooks';
// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import {renderHook} from '@testing-library/react';
import {usePrevious, useShallowMemoObject} from '../reactUtils';

describe('usePrevious', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/**
/**
* 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.
*
* @jest-environment jsdom
*/

import {renderHook} from '@testing-library/react-hooks';
// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import {renderHook} from '@testing-library/react';
import {useFilteredAndTreeifiedTOC, useTreeifiedTOC} from '../tocUtils';
import type {TOCItem} from '@docusaurus/mdx-loader';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {StaticRouter} from 'react-router-dom';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import {fromPartial} from '@total-typescript/shoehorn';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {StaticRouter} from 'react-router-dom';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import {useLocalPathname} from '../useLocalPathname';
Expand Down
Loading