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

nativeTerminalModule.test.ts

52 lines1.8 KB

1import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
2​
3const expoMocks = vi.hoisted(() => ({
4 requireNativeView: vi.fn(),
5}));
6const nativeView = () => null;
7const originalExpo = globalThis.expo;
8​
9function setExpoViewConfigAvailable() {
10 globalThis.expo = {
11 getViewConfig: vi.fn().mockReturnValue({ validAttributes: {}, directEventTypes: {} }),
12 } as unknown as typeof globalThis.expo;
14​
15vi.mock("expo", () => ({
16 requireNativeView: expoMocks.requireNativeView,
17}));
18​
19describe("resolveNativeTerminalSurfaceView", () => {
20 beforeEach(() => {
21 vi.clearAllMocks();
22 vi.resetModules();
23 globalThis.expo = undefined as unknown as typeof globalThis.expo;
24 });
25​
26 afterEach(() => {
27 globalThis.expo = originalExpo;
28 });
29​
30 it("returns null when the native terminal view config is unavailable", async () => {
31 const { resolveNativeTerminalSurfaceView } = await import("./nativeTerminalModule");
32 expect(resolveNativeTerminalSurfaceView()).toBeNull();
33 expect(expoMocks.requireNativeView).not.toHaveBeenCalled();
34 });
35​
36 it("returns the native terminal view when the view config is installed", async () => {
37 setExpoViewConfigAvailable();
38 expoMocks.requireNativeView.mockReturnValue(nativeView);
39 const { resolveNativeTerminalSurfaceView } = await import("./nativeTerminalModule");
40 expect(resolveNativeTerminalSurfaceView()).toBe(nativeView);
41 expect(expoMocks.requireNativeView).toHaveBeenCalledWith("T3TerminalSurface");
42 });
43​
44 it("returns null when the view manager cannot be required", async () => {
45 setExpoViewConfigAvailable();
46 expoMocks.requireNativeView.mockImplementation(() => {
47 throw new Error("boom");
48 });
49 const { resolveNativeTerminalSurfaceView } = await import("./nativeTerminalModule");
50 expect(resolveNativeTerminalSurfaceView()).toBeNull();
51 });
52});