mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-04-19 08:06:40 +02:00
Replace 'wait' with 'waitFor'
This commit is contained in:
parent
700b28c463
commit
326790d80d
@ -21,10 +21,7 @@ module.exports = {
|
|||||||
testPathIgnorePatterns: ["/node_modules/", "/__fixtures__/", "/dist/"],
|
testPathIgnorePatterns: ["/node_modules/", "/__fixtures__/", "/dist/"],
|
||||||
testEnvironment: "jsdom",
|
testEnvironment: "jsdom",
|
||||||
verbose: false,
|
verbose: false,
|
||||||
setupFilesAfterEnv: [
|
setupFilesAfterEnv: ["<rootDir>/src/testUtils/setup"],
|
||||||
"@testing-library/react/cleanup-after-each",
|
|
||||||
"<rootDir>/src/testUtils/setup",
|
|
||||||
],
|
|
||||||
globals: {
|
globals: {
|
||||||
TZ: "utc",
|
TZ: "utc",
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { render, fireEvent, getByLabelText, wait } from "customTestRender";
|
import { render, fireEvent, getByLabelText, waitFor } from "customTestRender";
|
||||||
|
|
||||||
import NumberInput from "../NumberInput";
|
import NumberInput from "../NumberInput";
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ describe("<NumberInput/>", () => {
|
|||||||
it("Increase number with button", async () => {
|
it("Increase number with button", async () => {
|
||||||
const increaseButton = getByLabelText(componentContainer, /Increase/);
|
const increaseButton = getByLabelText(componentContainer, /Increase/);
|
||||||
fireEvent.mouseDown(increaseButton);
|
fireEvent.mouseDown(increaseButton);
|
||||||
await wait(() =>
|
await waitFor(() =>
|
||||||
expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 2 } })
|
expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 2 } })
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -42,7 +42,7 @@ describe("<NumberInput/>", () => {
|
|||||||
it("Decrease number with button", async () => {
|
it("Decrease number with button", async () => {
|
||||||
const decreaseButton = getByLabelText(componentContainer, /Decrease/);
|
const decreaseButton = getByLabelText(componentContainer, /Decrease/);
|
||||||
fireEvent.mouseDown(decreaseButton);
|
fireEvent.mouseDown(decreaseButton);
|
||||||
await wait(() =>
|
await waitFor(() =>
|
||||||
expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 0 } })
|
expect(onChangeMock).toHaveBeenCalledWith({ target: { value: 0 } })
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2021 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { render, fireEvent, wait } from "customTestRender";
|
import { render, fireEvent, waitFor } from "customTestRender";
|
||||||
|
|
||||||
import mockAxios from "jest-mock-axios";
|
import mockAxios from "jest-mock-axios";
|
||||||
import WebSockets from "webSockets/WebSockets";
|
import WebSockets from "webSockets/WebSockets";
|
||||||
@ -35,7 +35,7 @@ describe("<ResetWiFiSettings/>", () => {
|
|||||||
expect.anything()
|
expect.anything()
|
||||||
);
|
);
|
||||||
mockAxios.mockResponse({ data: { foo: "bar" } });
|
mockAxios.mockResponse({ data: { foo: "bar" } });
|
||||||
await wait(() =>
|
await waitFor(() =>
|
||||||
expect(mockSetAlert).toBeCalledWith(
|
expect(mockSetAlert).toBeCalledWith(
|
||||||
"Wi-Fi settings are set to defaults.",
|
"Wi-Fi settings are set to defaults.",
|
||||||
ALERT_TYPES.SUCCESS
|
ALERT_TYPES.SUCCESS
|
||||||
@ -46,7 +46,7 @@ describe("<ResetWiFiSettings/>", () => {
|
|||||||
it("should display alert on open ports - failure", async () => {
|
it("should display alert on open ports - failure", async () => {
|
||||||
fireEvent.click(getAllByText("Reset Wi-Fi Settings")[1]);
|
fireEvent.click(getAllByText("Reset Wi-Fi Settings")[1]);
|
||||||
mockJSONError();
|
mockJSONError();
|
||||||
await wait(() =>
|
await waitFor(() =>
|
||||||
expect(mockSetAlert).toBeCalledWith(
|
expect(mockSetAlert).toBeCalledWith(
|
||||||
"An error occurred during resetting Wi-Fi settings."
|
"An error occurred during resetting Wi-Fi settings."
|
||||||
)
|
)
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2021 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import diffSnapshot from "snapshot-diff";
|
import diffSnapshot from "snapshot-diff";
|
||||||
import mockAxios from "jest-mock-axios";
|
import mockAxios from "jest-mock-axios";
|
||||||
|
|
||||||
import { fireEvent, render, wait } from "customTestRender";
|
import { fireEvent, render, waitFor } from "customTestRender";
|
||||||
import WebSockets from "webSockets/WebSockets";
|
import WebSockets from "webSockets/WebSockets";
|
||||||
import { mockJSONError } from "testUtils/network";
|
import { mockJSONError } from "testUtils/network";
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ describe("<WiFiSettings/>", () => {
|
|||||||
getByLabelText = renderRes.getByLabelText;
|
getByLabelText = renderRes.getByLabelText;
|
||||||
getByText = renderRes.getByText;
|
getByText = renderRes.getByText;
|
||||||
mockAxios.mockResponse({ data: wifiSettingsFixture() });
|
mockAxios.mockResponse({ data: wifiSettingsFixture() });
|
||||||
await wait(() => renderRes.getByText("Wi-Fi 1"));
|
await waitFor(() => renderRes.getByText("Wi-Fi 1"));
|
||||||
firstRender = renderRes.asFragment();
|
firstRender = renderRes.asFragment();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ describe("<WiFiSettings/>", () => {
|
|||||||
);
|
);
|
||||||
const errorMessage = "An API error occurred.";
|
const errorMessage = "An API error occurred.";
|
||||||
mockJSONError(errorMessage);
|
mockJSONError(errorMessage);
|
||||||
await wait(() => {
|
await waitFor(() => {
|
||||||
expect(getByText(errorMessage)).toBeTruthy();
|
expect(getByText(errorMessage)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
@ -9,13 +9,7 @@ import React from "react";
|
|||||||
|
|
||||||
import Button from "bootstrap/Button";
|
import Button from "bootstrap/Button";
|
||||||
|
|
||||||
import {
|
import { fireEvent, getByText, render, waitFor } from "customTestRender";
|
||||||
fireEvent,
|
|
||||||
getByText,
|
|
||||||
queryByText,
|
|
||||||
render,
|
|
||||||
wait,
|
|
||||||
} from "customTestRender";
|
|
||||||
import mockAxios from "jest-mock-axios";
|
import mockAxios from "jest-mock-axios";
|
||||||
import { mockJSONError } from "testUtils/network";
|
import { mockJSONError } from "testUtils/network";
|
||||||
import { mockSetAlert } from "testUtils/alertContextMock";
|
import { mockSetAlert } from "testUtils/alertContextMock";
|
||||||
@ -73,7 +67,7 @@ describe("<ActionButtonWithModal/>", () => {
|
|||||||
fireEvent.click(getByText(componentContainer, "Action"));
|
fireEvent.click(getByText(componentContainer, "Action"));
|
||||||
fireEvent.click(getByText(componentContainer, "Confirm action"));
|
fireEvent.click(getByText(componentContainer, "Confirm action"));
|
||||||
mockJSONError();
|
mockJSONError();
|
||||||
await wait(() =>
|
await waitFor(() =>
|
||||||
expect(mockSetAlert).toBeCalledWith("Action request failed.")
|
expect(mockSetAlert).toBeCalledWith("Action request failed.")
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -82,7 +76,7 @@ describe("<ActionButtonWithModal/>", () => {
|
|||||||
fireEvent.click(getByText(componentContainer, "Action"));
|
fireEvent.click(getByText(componentContainer, "Action"));
|
||||||
fireEvent.click(getByText(componentContainer, "Confirm action"));
|
fireEvent.click(getByText(componentContainer, "Confirm action"));
|
||||||
mockAxios.mockResponse({ status: 200 });
|
mockAxios.mockResponse({ status: 200 });
|
||||||
await wait(() =>
|
await waitFor(() =>
|
||||||
expect(mockSetAlert).toBeCalledWith(
|
expect(mockSetAlert).toBeCalledWith(
|
||||||
"Action request succeeded.",
|
"Action request succeeded.",
|
||||||
"success"
|
"success"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { render, wait, getByText } from "customTestRender";
|
import { render, waitFor, getByText } from "customTestRender";
|
||||||
import mockAxios from "jest-mock-axios";
|
import mockAxios from "jest-mock-axios";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -38,7 +38,7 @@ describe("CustomizationContext", () => {
|
|||||||
it("should render component without customization", async () => {
|
it("should render component without customization", async () => {
|
||||||
mockAxios.mockResponse({ data: {} });
|
mockAxios.mockResponse({ data: {} });
|
||||||
|
|
||||||
await wait(() => getByText(componentContainer, ORIGINAL));
|
await waitFor(() => getByText(componentContainer, ORIGINAL));
|
||||||
|
|
||||||
expect(componentContainer).toMatchSnapshot();
|
expect(componentContainer).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
@ -46,7 +46,7 @@ describe("CustomizationContext", () => {
|
|||||||
it("should render customized component", async () => {
|
it("should render customized component", async () => {
|
||||||
mockAxios.mockResponse({ data: { customization: "shield" } });
|
mockAxios.mockResponse({ data: { customization: "shield" } });
|
||||||
|
|
||||||
await wait(() => getByText(componentContainer, CUSTOM));
|
await waitFor(() => getByText(componentContainer, CUSTOM));
|
||||||
|
|
||||||
expect(componentContainer).toMatchSnapshot();
|
expect(componentContainer).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
* Copyright (C) 2019-2025 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||||
*
|
*
|
||||||
* This is free software, licensed under the GNU General Public License v3.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { act, fireEvent, render, waitForElement } from "customTestRender";
|
import { act, fireEvent, render, waitFor } from "customTestRender";
|
||||||
import mockAxios from "jest-mock-axios";
|
import mockAxios from "jest-mock-axios";
|
||||||
import WebSockets from "webSockets/WebSockets";
|
import WebSockets from "webSockets/WebSockets";
|
||||||
import ForisForm from "../components/ForisForm";
|
import ForisForm from "../components/ForisForm";
|
||||||
@ -59,7 +59,7 @@ describe("useForm hook.", () => {
|
|||||||
);
|
);
|
||||||
mockAxios.mockResponse({ field: "fetchedData" });
|
mockAxios.mockResponse({ field: "fetchedData" });
|
||||||
|
|
||||||
input = await waitForElement(() => getByTestId("test-input"));
|
input = await waitFor(() => getByTestId("test-input"));
|
||||||
form = container.firstChild.firstChild;
|
form = container.firstChild.firstChild;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user