Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestPresentation.test.tsx

28 lines915 Bytes

1import { act } from "react";
2import { create, type ReactTestRenderer } from "react-test-renderer";
3import { afterEach, expect, it, vi } from "vite-plus/test";
4​
5import { PullRequestActorAvatar } from "./pullRequestPresentation";
6​
7let renderer: ReactTestRenderer | undefined;
8​
9afterEach(async () => {
10 await act(async () => renderer?.unmount());
11 vi.unstubAllGlobals();
12});
13​
14it("falls back to the actor initial when a remote avatar fails", async () => {
15 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
16 await act(async () => {
17 renderer = create(
18 <PullRequestActorAvatar
19 actor={{ login: "octocat", name: null, avatarUrl: "https://ghe.example/octocat.png" }}
20 />,
21 );
22 });
23​
24 await act(async () => renderer!.root.findByType("img").props.onError());
25​
26 expect(renderer!.root.findAllByType("img")).toHaveLength(0);
27 expect(renderer!.root.findByType("span").children).toEqual(["O"]);
28});