test(web): fix tests to conform to react18 (#3466)

This change drops the use of ReactDOM which is not supported in React 18. We also fix any test warnings related to i18next.
pull/3467/head
Amir Zarrinkafsh 2022-06-03 10:17:00 +10:00 committed by GitHub
parent f07f6b7dda
commit bbeab861b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 9 deletions

View File

@ -3,6 +3,7 @@ import React from "react";
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import App from "@root/App"; import App from "@root/App";
import "@i18n/index.ts";
it("renders without crashing", () => { it("renders without crashing", () => {
render(<App />); render(<App />);

View File

@ -1,11 +1,9 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import { render } from "@testing-library/react";
import AppStoreBadges from "@components/AppStoreBadges"; import AppStoreBadges from "@components/AppStoreBadges";
it("renders without crashing", () => { it("renders without crashing", () => {
const div = document.createElement("div"); render(<AppStoreBadges iconSize={32} appleStoreLink="http://apple" googlePlayLink="http://google" />);
ReactDOM.render(<AppStoreBadges iconSize={32} appleStoreLink="http://apple" googlePlayLink="http://google" />, div);
ReactDOM.unmountComponentAtNode(div);
}); });

View File

@ -1,14 +1,12 @@
import React from "react"; import React from "react";
import { render, screen } from "@testing-library/react"; import { render, screen } from "@testing-library/react";
import ReactDOM from "react-dom";
import ColoredSnackbarContent from "@components/ColoredSnackbarContent"; import ColoredSnackbarContent from "@components/ColoredSnackbarContent";
it("renders without crashing", () => { it("renders without crashing", () => {
const div = document.createElement("div"); render(<ColoredSnackbarContent level="success" message="" />);
ReactDOM.render(<ColoredSnackbarContent level="success" message="this is a success" />, div); expect(screen.getByRole("alert")).toHaveTextContent("");
ReactDOM.unmountComponentAtNode(div);
}); });
it("should contain the message", () => { it("should contain the message", () => {

View File

@ -3,6 +3,7 @@ import React from "react";
import { render } from "@testing-library/react"; import { render } from "@testing-library/react";
import PasswordMeter from "@components/PasswordMeter"; import PasswordMeter from "@components/PasswordMeter";
import "@i18n/index.ts";
import { PasswordPolicyMode } from "@models/PasswordPolicy"; import { PasswordPolicyMode } from "@models/PasswordPolicy";
it("renders without crashing", () => { it("renders without crashing", () => {

View File

@ -17,7 +17,7 @@ const PasswordMeter = function (props: Props) {
const [passwordScore, setPasswordScore] = useState(0); const [passwordScore, setPasswordScore] = useState(0);
const [maxScores, setMaxScores] = useState(0); const [maxScores, setMaxScores] = useState(0);
const [feedback, setFeedback] = useState(""); const [feedback, setFeedback] = useState("");
const { t: translate } = useTranslation("Portal"); const { t: translate } = useTranslation();
const style = makeStyles((theme) => ({ const style = makeStyles((theme) => ({
progressBar: { progressBar: {
height: "5px", height: "5px",