@truedat/test 8.12.5 → 8.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/package.json +2 -2
- package/src/__tests__/renderWithIntl.spec.js +20 -0
- package/src/render.js +2 -13
- package/src/renderWithIntl.js +28 -0
- package/src/waitForLoad.js +13 -0
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
# Truedat Web Test
|
|
2
2
|
|
|
3
3
|
Testing support for Truedat Web Modules.
|
|
4
|
+
|
|
5
|
+
Use `renderWithIntl` from `@truedat/test/renderWithIntl` for components that only
|
|
6
|
+
need internationalization. It accepts `locale`, `messages` keyed by locale, and
|
|
7
|
+
Testing Library render options. Pass `fallback` to add a Suspense boundary for
|
|
8
|
+
components that suspend. It does not install fake timers; configure timers and
|
|
9
|
+
the clock explicitly in tests that need them.
|
|
10
|
+
|
|
11
|
+
Import `waitForLoad` from `@truedat/test/waitForLoad` when a component has loading
|
|
12
|
+
indicators. This standalone helper does not mount providers or install timers.
|
|
13
|
+
|
|
14
|
+
Use Testing Library's plain `render` for components without provider dependencies.
|
|
15
|
+
Use `render` from `@truedat/test/render` when tests need the full Redux, Apollo,
|
|
16
|
+
router, and internationalization setup.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/test",
|
|
3
|
-
"version": "8.12.
|
|
3
|
+
"version": "8.12.7",
|
|
4
4
|
"description": "Truedat Web Test",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"react-router": "^8.3.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "dae06fd2f915163d5f1e7e3f26c414c8ee9bf055"
|
|
70
70
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { lazy } from "react";
|
|
2
|
+
import { FormattedMessage } from "react-intl";
|
|
3
|
+
import { renderWithIntl } from "../renderWithIntl";
|
|
4
|
+
|
|
5
|
+
describe("renderWithIntl", () => {
|
|
6
|
+
it("keeps the Suspense boundary and messages when rerendering", async () => {
|
|
7
|
+
const LazyMessage = lazy(async () => ({
|
|
8
|
+
default: () => <FormattedMessage id="ready" />,
|
|
9
|
+
}));
|
|
10
|
+
const rendered = renderWithIntl(<div>Initial</div>, {
|
|
11
|
+
messages: { en: { ready: "Ready" } },
|
|
12
|
+
fallback: <div>Loading</div>,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
rendered.rerender(<LazyMessage />);
|
|
16
|
+
|
|
17
|
+
expect(rendered.getByText("Loading")).toBeInTheDocument();
|
|
18
|
+
expect(await rendered.findByText("Ready")).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/render.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Suspense } from "react";
|
|
2
2
|
import { MockedProvider } from "@apollo/client/testing";
|
|
3
|
-
import { render
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
4
|
import { IntlProvider } from "react-intl";
|
|
5
5
|
import { configureStore } from "@reduxjs/toolkit";
|
|
6
6
|
import { Provider } from "react-redux";
|
|
@@ -82,16 +82,5 @@ const customRender = (
|
|
|
82
82
|
return render(component, { wrapper: Wrapper, ...renderOptions });
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
export
|
|
86
|
-
{ container, queryByText },
|
|
87
|
-
fallback = /loading/i,
|
|
88
|
-
options,
|
|
89
|
-
) => {
|
|
90
|
-
await waitFor(() => {
|
|
91
|
-
if (fallback) expect(queryByText(fallback)).not.toBeInTheDocument();
|
|
92
|
-
expect(container.querySelector(".loader")).not.toBeInTheDocument();
|
|
93
|
-
expect(container.querySelector(".loading")).not.toBeInTheDocument();
|
|
94
|
-
}, options);
|
|
95
|
-
};
|
|
96
|
-
|
|
85
|
+
export { waitForLoad } from "./waitForLoad";
|
|
97
86
|
export { customRender as render };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Suspense } from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { IntlProvider } from "react-intl";
|
|
4
|
+
|
|
5
|
+
export const renderWithIntl = (
|
|
6
|
+
component,
|
|
7
|
+
{ locale = "en", messages = { en: {} }, fallback, ...renderOptions } = {},
|
|
8
|
+
) => {
|
|
9
|
+
// eslint-disable-next-line react/prop-types
|
|
10
|
+
function Wrapper({ children }) {
|
|
11
|
+
return (
|
|
12
|
+
<IntlProvider
|
|
13
|
+
onError={() => {}}
|
|
14
|
+
locale={locale}
|
|
15
|
+
defaultLocale={locale}
|
|
16
|
+
messages={messages[locale]}
|
|
17
|
+
>
|
|
18
|
+
{fallback === undefined ? (
|
|
19
|
+
children
|
|
20
|
+
) : (
|
|
21
|
+
<Suspense fallback={fallback}>{children}</Suspense>
|
|
22
|
+
)}
|
|
23
|
+
</IntlProvider>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return render(component, { wrapper: Wrapper, ...renderOptions });
|
|
28
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { waitFor } from "@testing-library/react";
|
|
2
|
+
|
|
3
|
+
export const waitForLoad = async (
|
|
4
|
+
{ container, queryByText },
|
|
5
|
+
fallback = /loading/i,
|
|
6
|
+
options,
|
|
7
|
+
) => {
|
|
8
|
+
await waitFor(() => {
|
|
9
|
+
if (fallback) expect(queryByText(fallback)).not.toBeInTheDocument();
|
|
10
|
+
expect(container.querySelector(".loader")).not.toBeInTheDocument();
|
|
11
|
+
expect(container.querySelector(".loading")).not.toBeInTheDocument();
|
|
12
|
+
}, options);
|
|
13
|
+
};
|