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

foreground-handoff.test.ts

32 lines1.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { beginForegroundHandoff, isForegroundHandoffActive } from "./foreground-handoff";
4​
5describe("foreground handoff", () => {
6 it("is active only while a handoff is open", () => {
7 expect(isForegroundHandoffActive()).toBe(false);
8 const end = beginForegroundHandoff();
9 expect(isForegroundHandoffActive()).toBe(true);
10 end();
11 expect(isForegroundHandoffActive()).toBe(false);
12 });
13​
14 it("stays active until every overlapping handoff ends", () => {
15 const endFirst = beginForegroundHandoff();
16 const endSecond = beginForegroundHandoff();
17 endFirst();
18 expect(isForegroundHandoffActive()).toBe(true);
19 endSecond();
20 expect(isForegroundHandoffActive()).toBe(false);
21 });
22​
23 it("tolerates an end function called twice", () => {
24 const endFirst = beginForegroundHandoff();
25 const endSecond = beginForegroundHandoff();
26 endFirst();
27 endFirst();
28 expect(isForegroundHandoffActive()).toBe(true);
29 endSecond();
30 expect(isForegroundHandoffActive()).toBe(false);
31 });
32});