From 5174abd0e4abc0ef78d41484a3654673e8eca9f7 Mon Sep 17 00:00:00 2001
From: Daniel Tschinder <231804+danez@users.noreply.github.com>
Date: Wed, 18 Dec 2024 12:46:36 +0100
Subject: [PATCH] chore: migrate to react-testing library
---
package.json | 1 -
pnpm-lock.yaml | 26 -----
src/components/__tests__/Tab-test.js | 5 +-
src/components/__tests__/TabList-test.js | 5 +-
src/components/__tests__/TabPanel-test.js | 5 +-
.../__tests__/__snapshots__/Tab-test.js.snap | 53 ++++------
.../__snapshots__/TabList-test.js.snap | 100 ++++++++----------
.../__snapshots__/TabPanel-test.js.snap | 18 ++--
8 files changed, 85 insertions(+), 128 deletions(-)
diff --git a/package.json b/package.json
index d894a3ceb9..7286ca88a1 100644
--- a/package.json
+++ b/package.json
@@ -83,7 +83,6 @@
"react-dom": "18.3.1",
"react-live": "4.1.8",
"react-modal": "3.16.3",
- "react-test-renderer": "18.3.1",
"webpack": "5.97.1",
"webpack-cli": "5.1.4",
"webpack-dev-server": "5.2.0"
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 886889302e..1a9006a431 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -120,9 +120,6 @@ importers:
react-modal:
specifier: 3.16.3
version: 3.16.3(react-dom@18.3.1(react@18.3.1))(react@18.3.1)
- react-test-renderer:
- specifier: 18.3.1
- version: 18.3.1(react@18.3.1)
webpack:
specifier: 5.97.1
version: 5.97.1(webpack-cli@5.1.4)
@@ -3651,16 +3648,6 @@ packages:
react: ^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19
react-dom: ^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19
- react-shallow-renderer@16.15.0:
- resolution: {integrity: sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA==}
- peerDependencies:
- react: ^16.0.0 || ^17.0.0 || ^18.0.0
-
- react-test-renderer@18.3.1:
- resolution: {integrity: sha512-KkAgygexHUkQqtvvx/otwxtuFu5cVjfzTCtjXLH9boS19/Nbtg84zS7wIQn39G8IlrhThBpQsMKkq5ZHZIYFXA==}
- peerDependencies:
- react: ^18.3.1
-
react@18.3.1:
resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==}
engines: {node: '>=0.10.0'}
@@ -8630,19 +8617,6 @@ snapshots:
react-lifecycles-compat: 3.0.4
warning: 4.0.3
- react-shallow-renderer@16.15.0(react@18.3.1):
- dependencies:
- object-assign: 4.1.1
- react: 18.3.1
- react-is: 18.3.1
-
- react-test-renderer@18.3.1(react@18.3.1):
- dependencies:
- react: 18.3.1
- react-is: 18.3.1
- react-shallow-renderer: 16.15.0(react@18.3.1)
- scheduler: 0.23.2
-
react@18.3.1:
dependencies:
loose-envify: 1.4.0
diff --git a/src/components/__tests__/Tab-test.js b/src/components/__tests__/Tab-test.js
index 6b3d00e6a8..bbf55c7c79 100644
--- a/src/components/__tests__/Tab-test.js
+++ b/src/components/__tests__/Tab-test.js
@@ -1,10 +1,11 @@
import React from 'react';
-import renderer from 'react-test-renderer';
+import { render } from '@testing-library/react';
import Tab from '../Tab';
import { TabWrapper } from './helpers/higherOrder';
function expectToMatchSnapshot(component) {
- expect(renderer.create(component).toJSON()).toMatchSnapshot();
+ const { container } = render(component);
+ expect(container.firstChild).toMatchSnapshot();
}
describe('', () => {
diff --git a/src/components/__tests__/TabList-test.js b/src/components/__tests__/TabList-test.js
index ed9552c140..3b0d016186 100644
--- a/src/components/__tests__/TabList-test.js
+++ b/src/components/__tests__/TabList-test.js
@@ -1,5 +1,5 @@
import React from 'react';
-import renderer from 'react-test-renderer';
+import { render } from '@testing-library/react';
import Tab from '../Tab';
import TabList from '../TabList';
import TabPanel from '../TabPanel';
@@ -16,7 +16,8 @@ jest.mock('react', () => {
});
function expectToMatchSnapshot(component) {
- expect(renderer.create(component).toJSON()).toMatchSnapshot();
+ const { container } = render(component);
+ expect(container.firstChild).toMatchSnapshot();
}
describe('', () => {
diff --git a/src/components/__tests__/TabPanel-test.js b/src/components/__tests__/TabPanel-test.js
index b8a7a80994..571a3a3e1f 100644
--- a/src/components/__tests__/TabPanel-test.js
+++ b/src/components/__tests__/TabPanel-test.js
@@ -1,10 +1,11 @@
import React from 'react';
-import renderer from 'react-test-renderer';
+import { render } from '@testing-library/react';
import TabPanel from '../TabPanel';
import { TabPanelWrapper } from './helpers/higherOrder';
function expectToMatchSnapshot(component) {
- expect(renderer.create(component).toJSON()).toMatchSnapshot();
+ const { container } = render(component);
+ expect(container.firstChild).toMatchSnapshot();
}
describe('', () => {
diff --git a/src/components/__tests__/__snapshots__/Tab-test.js.snap b/src/components/__tests__/__snapshots__/Tab-test.js.snap
index ebf635d1bb..8fa291e9cb 100644
--- a/src/components/__tests__/__snapshots__/Tab-test.js.snap
+++ b/src/components/__tests__/__snapshots__/Tab-test.js.snap
@@ -5,11 +5,11 @@ exports[` override the tabIndex if it was provided 1`] = `
aria-controls="panelnull"
aria-disabled="false"
aria-selected="false"
- className="react-tabs__tab"
- data-rttab={true}
+ class="react-tabs__tab"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex="0"
+ tabindex="0"
>
Hello
@@ -20,11 +20,10 @@ exports[` should accept className 1`] = `
aria-controls="panelnull"
aria-disabled="false"
aria-selected="false"
- className="foobar"
- data-rttab={true}
+ class="foobar"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex={null}
/>
`;
@@ -33,11 +32,10 @@ exports[` should allow to be wrapped in higher-order-component 1`] = `
aria-controls="panelnull"
aria-disabled="false"
aria-selected="false"
- className="react-tabs__tab"
- data-rttab={true}
+ class="react-tabs__tab"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex={null}
/>
`;
@@ -46,11 +44,10 @@ exports[` should have sane defaults 1`] = `
aria-controls="panelnull"
aria-disabled="false"
aria-selected="false"
- className="react-tabs__tab"
- data-rttab={true}
+ class="react-tabs__tab"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex={null}
/>
`;
@@ -59,11 +56,10 @@ exports[` should not allow overriding all default properties 1`] = `
aria-controls="panelnull"
aria-disabled="false"
aria-selected="false"
- className="react-tabs__tab"
- data-rttab={true}
+ class="react-tabs__tab"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex={null}
/>
`;
@@ -72,12 +68,11 @@ exports[` should pass through custom properties 1`] = `
aria-controls="panelnull"
aria-disabled="false"
aria-selected="false"
- className="react-tabs__tab"
- data-rttab={true}
+ class="react-tabs__tab"
+ data-rttab="true"
data-tooltip="Tooltip contents"
id="tabnull"
role="tab"
- tabIndex={null}
/>
`;
@@ -86,11 +81,10 @@ exports[` should support being disabled 1`] = `
aria-controls="panelnull"
aria-disabled="true"
aria-selected="false"
- className="react-tabs__tab react-tabs__tab--disabled"
- data-rttab={true}
+ class="react-tabs__tab react-tabs__tab--disabled"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex={null}
/>
`;
@@ -99,11 +93,10 @@ exports[` should support being disabled with custom class name 1`] = `
aria-controls="panelnull"
aria-disabled="true"
aria-selected="false"
- className="react-tabs__tab coolDisabled"
- data-rttab={true}
+ class="react-tabs__tab coolDisabled"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex={null}
/>
`;
@@ -112,11 +105,11 @@ exports[` should support being selected 1`] = `
aria-controls="panelabcd"
aria-disabled="false"
aria-selected="true"
- className="react-tabs__tab react-tabs__tab--selected"
- data-rttab={true}
+ class="react-tabs__tab react-tabs__tab--selected"
+ data-rttab="true"
id="tababcd"
role="tab"
- tabIndex="0"
+ tabindex="0"
>
Hello
@@ -127,10 +120,10 @@ exports[` should support being selected with custom class 1`] = `
aria-controls="panelnull"
aria-disabled="false"
aria-selected="true"
- className="react-tabs__tab cool"
- data-rttab={true}
+ class="react-tabs__tab cool"
+ data-rttab="true"
id="tabnull"
role="tab"
- tabIndex="0"
+ tabindex="0"
/>
`;
diff --git a/src/components/__tests__/__snapshots__/TabList-test.js.snap b/src/components/__tests__/__snapshots__/TabList-test.js.snap
index 1234211d08..2fba3c6927 100644
--- a/src/components/__tests__/__snapshots__/TabList-test.js.snap
+++ b/src/components/__tests__/__snapshots__/TabList-test.js.snap
@@ -2,31 +2,29 @@
exports[` should accept className 1`] = `
`;
exports[` should allow for higher order components 1`] = `
-
Foo
@@ -34,18 +32,17 @@ exports[` should allow for higher order components 1`] = `
aria-controls="panel:r0:1"
aria-disabled="false"
aria-selected="false"
- className="react-tabs__tab"
- data-rttab={true}
+ class="react-tabs__tab"
+ data-rttab="true"
id="tab:r0:1"
role="tab"
- tabIndex={null}
>
Bar
@@ -53,7 +50,7 @@ exports[` should allow for higher order components 1`] = `
@@ -62,24 +59,22 @@ exports[`
should allow for higher order components 1`] = `
exports[`
should display the custom classnames for selected and disabled tab 1`] = `
-
Foo
@@ -87,18 +82,17 @@ exports[` should display the custom classnames for selected and disab
aria-controls="panel:r0:1"
aria-disabled="true"
aria-selected="false"
- className="react-tabs__tab disabled"
- data-rttab={true}
+ class="react-tabs__tab disabled"
+ data-rttab="true"
id="tab:r0:1"
role="tab"
- tabIndex={null}
>
Bar
@@ -106,7 +100,7 @@ exports[` should display the custom classnames for selected and disab
@@ -115,24 +109,22 @@ exports[`
should display the custom classnames for selected and disab
exports[`
should display the custom classnames for selected and disabled tab specified on tabs 1`] = `
-
Foo
@@ -140,18 +132,17 @@ exports[` should display the custom classnames for selected and disab
aria-controls="panel:r0:1"
aria-disabled="true"
aria-selected="false"
- className="react-tabs__tab disabled"
- data-rttab={true}
+ class="react-tabs__tab disabled"
+ data-rttab="true"
id="tab:r0:1"
role="tab"
- tabIndex={null}
>
Bar
@@ -159,7 +150,7 @@ exports[` should display the custom classnames for selected and disab
@@ -168,21 +159,21 @@ exports[`
should display the custom classnames for selected and disab
exports[`
should have sane defaults 1`] = `
`;
exports[`
should not allow overriding all default properties 1`] = `
`;
exports[`
should pass through custom properties 1`] = `
@@ -190,24 +181,22 @@ exports[`
should pass through custom properties 1`] = `
exports[`
should retain the default classnames for active and disabled tab 1`] = `
-
Foo
@@ -215,18 +204,17 @@ exports[` should retain the default classnames for active and disable
aria-controls="panel:r0:1"
aria-disabled="true"
aria-selected="false"
- className="react-tabs__tab react-tabs__tab--disabled"
- data-rttab={true}
+ class="react-tabs__tab react-tabs__tab--disabled"
+ data-rttab="true"
id="tab:r0:1"
role="tab"
- tabIndex={null}
>
Bar
@@ -234,7 +222,7 @@ exports[` should retain the default classnames for active and disable
diff --git a/src/components/__tests__/__snapshots__/TabPanel-test.js.snap b/src/components/__tests__/__snapshots__/TabPanel-test.js.snap
index 4c4f1d1260..de670ac8df 100644
--- a/src/components/__tests__/__snapshots__/TabPanel-test.js.snap
+++ b/src/components/__tests__/__snapshots__/TabPanel-test.js.snap
@@ -3,7 +3,7 @@
exports[`
should accept className 1`] = `
@@ -12,7 +12,7 @@ exports[`
should accept className 1`] = `
exports[`
should allow for higher-order components 1`] = `
@@ -21,7 +21,7 @@ exports[`
should allow for higher-order components 1`] = `
exports[`
should have sane defaults 1`] = `
@@ -30,7 +30,7 @@ exports[`
should have sane defaults 1`] = `
exports[`
should not allow overriding all default properties 1`] = `
@@ -39,7 +39,7 @@ exports[`
should not allow overriding all default properties 1`] = `
exports[`
should pass through custom properties 1`] = `
should pass through custom properties 1`] = `
exports[`
should render when forced 1`] = `
@@ -60,7 +60,7 @@ exports[`
should render when forced 1`] = `
exports[`
should render when selected 1`] = `
@@ -71,7 +71,7 @@ exports[`
should render when selected 1`] = `
exports[`
should support being selected 1`] = `
@@ -82,7 +82,7 @@ exports[`
should support being selected 1`] = `
exports[`
should support being selected with custom class name 1`] = `