PHP Classes

File: src/components/badge/__tests__/Badge.test.tsx

Recommend this page to a friend!
  Classes of Maniruzzaman Akash   WordPress React Plugin Kit   src/components/badge/__tests__/Badge.test.tsx   Download  
File: src/components/badge/__tests__/Badge.test.tsx
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: WordPress React Plugin Kit
Environment to develop new WordPress plugins
Author: By
Last change:
Date: 2 years ago
Size: 1,218 bytes
 

Contents

Class file image Download
/** * External dependencies */ import { render, screen } from "@testing-library/react"; /** * Internal dependencies. */ import Badge from "../Badge"; import SvgCirclePrimaryIcon from "../../svg/SvgCirclePrimaryIcon"; const props = { text: "Simple Badge", type: "primary" }; const renderBadge = (customProps = {}) => { return render(<Badge {...{ ...props, ...customProps }} />); }; describe("Badge", () => { it("should render without crashing", () => { renderBadge(); const badgeText = screen.getByText(props.text); expect(badgeText).toBeInTheDocument(); }); // Check hasIcon prop and svgIcon is given or not. it("should render svg icon if hasIcon is true", () => { const { container } = renderBadge({ hasIcon: true, svgIcon: SvgCirclePrimaryIcon }); const svgIcon = container.querySelector("svg"); expect(svgIcon).toBeInTheDocument(); }); // Check if customClass is given and the class is present or not. it("should render with custom class if it has been given", () => { const customClass = "bg-red-500"; const { container } = renderBadge({ customClass }); expect(container.firstChild).toHaveClass(customClass); }); });