Skip to content

Commit 9e9c0af

Browse files
committed
test: refactor tests
1 parent aa1ad12 commit 9e9c0af

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

test/Lightbox.spec.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createContext, createElement } from "react";
2-
import { describe, expect, it } from "vitest";
2+
import { describe, expect, it, vi } from "vitest";
33
import { render, screen } from "@testing-library/react";
44
import { userEvent } from "@testing-library/user-event";
55

@@ -29,7 +29,7 @@ import {
2929
wheelZoom,
3030
withFakeTimers,
3131
} from "./test-utils";
32-
import { useZoom } from "../src/components";
32+
import { useZoom } from "../src";
3333
import { makeUseContext } from "../src/utils";
3434

3535
declare module "../src/types" {
@@ -206,25 +206,31 @@ describe("Lightbox", () => {
206206
});
207207

208208
it("supports view transitions", () => {
209-
document.startViewTransition = (callback) => {
209+
const startViewTransitionBackup = document.startViewTransition;
210+
211+
document.startViewTransition = vi.fn().mockImplementation((callback) => {
210212
callback?.();
211213

212214
return {
213215
ready: Promise.resolve(undefined),
214216
finished: Promise.resolve(undefined),
215217
updateCallbackDone: Promise.resolve(undefined),
216218
skipTransition() {},
217-
};
218-
};
219+
types: {
220+
forEach() {},
221+
},
222+
} satisfies ViewTransition;
223+
});
219224

220225
renderLightbox();
221226
expectCurrentSlideToBe(0);
222227

223228
clickButtonNext();
224229
expectCurrentSlideToBe(1);
225230

226-
// @ts-expect-error - expected error
227-
document.startViewTransition = undefined;
231+
expect(document.startViewTransition).toHaveBeenCalled();
232+
233+
document.startViewTransition = startViewTransitionBackup;
228234
});
229235

230236
it("supports custom styles", () => {

0 commit comments

Comments
 (0)