mirror of
https://github.com/igorski/bitmappery.git
synced 2026-07-27 09:17:38 +02:00
Restructure test mocks
This commit is contained in:
@@ -81,15 +81,23 @@ export function createMockCanvasElement(): HTMLCanvasElement {
|
||||
const cvs = {
|
||||
width: 300,
|
||||
height: 200,
|
||||
getContext: vi.fn().mockImplementation(() => ctx ),
|
||||
getContext: () => ctx,
|
||||
} as unknown as HTMLCanvasElement;
|
||||
|
||||
|
||||
// @ts-expect-error cannot assign to read only property
|
||||
ctx.canvas = cvs;
|
||||
|
||||
return cvs;
|
||||
}
|
||||
|
||||
export function mockCanvasConstructor(): void {
|
||||
vi.spyOn( document, "createElement" ).mockImplementation( type => {
|
||||
if ( type === "canvas" ) {
|
||||
return createMockCanvasElement() as HTMLElement;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute calls debounced by requestAnimationFrame() to use timeouts, which allows
|
||||
* us to throttle these with vi.useFakeTimers();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createMockCanvasElement, createMockZoomableCanvas, mockZCanvas } from "../../mocks";
|
||||
import { createMockCanvasElement, createMockZoomableCanvas, mockCanvasConstructor, mockZCanvas } from "../../mocks";
|
||||
mockZCanvas();
|
||||
|
||||
import { type Store } from "vuex";
|
||||
@@ -49,11 +49,7 @@ describe( "LayerSprite", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.spyOn( document, "createElement" ).mockImplementation( type => {
|
||||
if ( type === "canvas" ) {
|
||||
return createMockCanvasElement() as HTMLElement;
|
||||
}
|
||||
});
|
||||
mockCanvasConstructor();
|
||||
|
||||
layer = LayerFactory.create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user