From cdac8bd96a6b0f9c3b2ad6d2cfc72e9a85073917 Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 26 Sep 2023 09:01:05 +0200 Subject: [PATCH 1/2] feat(chore): add avatar test --- src/components/avatar/avatar.test.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/components/avatar/avatar.test.tsx diff --git a/src/components/avatar/avatar.test.tsx b/src/components/avatar/avatar.test.tsx new file mode 100644 index 00000000..3f50aef8 --- /dev/null +++ b/src/components/avatar/avatar.test.tsx @@ -0,0 +1,16 @@ +import { describe, expect, it } from "vitest"; +import { getByText, render, screen } from "@testing-library/react"; +import React from "react"; +import { Avatar } from "./avatar"; + +describe("Avatar", () => { + it("renders an avatar with substring of child", () => { + // ARRANGE + render(Test User); + + // ASSERT + const alert = screen.getByRole("button"); + expect(alert).toBeInTheDocument(); + expect(getByText(alert, "Te")).toBeInTheDocument(); + }); +}); From 9375da7d546cc814382d15e7571bf07c8b5646dd Mon Sep 17 00:00:00 2001 From: Manuel Date: Wed, 27 Sep 2023 09:11:26 +0200 Subject: [PATCH 2/2] fix(chore): extract text to new variable --- src/components/avatar/avatar.test.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/avatar/avatar.test.tsx b/src/components/avatar/avatar.test.tsx index 3f50aef8..804f63ed 100644 --- a/src/components/avatar/avatar.test.tsx +++ b/src/components/avatar/avatar.test.tsx @@ -5,8 +5,9 @@ import { Avatar } from "./avatar"; describe("Avatar", () => { it("renders an avatar with substring of child", () => { + const text = "Test User"; // ARRANGE - render(Test User); + render({text}); // ASSERT const alert = screen.getByRole("button");