/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import { render } from "@testing-library/react"; import { createMemoryHistory } from "history"; import { Router } from "react-router-dom"; import { LocationState } from "../../models"; import AlertContainer from "../AlertContainer"; test("displays an alert when location.state contains an alert", () => { const history = createMemoryHistory(); history.push("/whatever", { alert: { type: "success", message: "Hello this is an alert", }, }); const { getByText } = render( , ); expect(getByText("Hello this is an alert")).toBeInTheDocument(); }); test("displays nothing when no alert in location.state", () => { const history = createMemoryHistory(); history.push("/whatever", {}); const wrapper = render( , ); expect(wrapper.container).toMatchSnapshot(); });