From ce9a75f074a87815850d34bff8c33e6e6b06be0a Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Wed, 11 Sep 2024 13:54:42 -0700 Subject: [PATCH] Replace `vi.fn()` with `() => null` whenenver possible (#4182) --- src/test/utils/gameWrapper.ts | 2 +- src/test/utils/mocks/mockGameObjectCreator.ts | 5 ++--- src/test/utils/mocks/mockVideoGameObject.ts | 11 +++++------ src/test/utils/mocks/mocksContainer/mockContainer.ts | 10 ++++------ src/test/utils/mocks/mocksContainer/mockSprite.ts | 3 +-- src/test/utils/mocks/mocksContainer/mockText.ts | 11 +++++------ 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/test/utils/gameWrapper.ts b/src/test/utils/gameWrapper.ts index f3098fa9b71..1cf01a3a8c8 100644 --- a/src/test/utils/gameWrapper.ts +++ b/src/test/utils/gameWrapper.ts @@ -41,7 +41,7 @@ window.URL.createObjectURL = (blob: Blob) => { }); return null; }; -navigator.getGamepads = vi.fn().mockReturnValue([]); +navigator.getGamepads = () => []; global.fetch = vi.fn(MockFetch); Utils.setCookie(Utils.sessionIdKey, 'fake_token'); diff --git a/src/test/utils/mocks/mockGameObjectCreator.ts b/src/test/utils/mocks/mockGameObjectCreator.ts index 19406a46923..27860be0cec 100644 --- a/src/test/utils/mocks/mockGameObjectCreator.ts +++ b/src/test/utils/mocks/mockGameObjectCreator.ts @@ -1,4 +1,3 @@ -import { vi } from "vitest"; import MockGraphics from "./mocksContainer/mockGraphics"; import MockTextureManager from "./mockTextureManager"; @@ -16,8 +15,8 @@ export class MockGameObjectCreator { rexTransitionImagePack() { return { - transit: vi.fn(), - once: vi.fn(), + transit: () => null, + once: () => null, }; } } diff --git a/src/test/utils/mocks/mockVideoGameObject.ts b/src/test/utils/mocks/mockVideoGameObject.ts index 96f03542bbc..d8155e23b6c 100644 --- a/src/test/utils/mocks/mockVideoGameObject.ts +++ b/src/test/utils/mocks/mockVideoGameObject.ts @@ -1,13 +1,12 @@ -import { vi } from "vitest"; import { MockGameObject } from "./mockGameObject"; /** Mocks video-related stuff */ export class MockVideoGameObject implements MockGameObject { constructor() {} - public play = vi.fn(); - public stop = vi.fn(() => this); - public setOrigin = vi.fn(); - public setScale = vi.fn(); - public setVisible = vi.fn(); + public play = () => null; + public stop = () => this; + public setOrigin = () => null; + public setScale = () => null; + public setVisible = () => null; } diff --git a/src/test/utils/mocks/mocksContainer/mockContainer.ts b/src/test/utils/mocks/mocksContainer/mockContainer.ts index 94ae61a6ce4..e13cef0e43e 100644 --- a/src/test/utils/mocks/mocksContainer/mockContainer.ts +++ b/src/test/utils/mocks/mocksContainer/mockContainer.ts @@ -1,5 +1,4 @@ import MockTextureManager from "#test/utils/mocks/mockTextureManager"; -import { vi } from "vitest"; import { MockGameObject } from "../mockGameObject"; export default class MockContainer implements MockGameObject { @@ -52,7 +51,7 @@ export default class MockContainer implements MockGameObject { /// Sets the position of this Game Object to be a relative position from the source Game Object. } - setInteractive = vi.fn(); + setInteractive = () => null; setOrigin(x, y) { this.x = x; @@ -160,10 +159,9 @@ export default class MockContainer implements MockGameObject { // Moves this Game Object to be below the given Game Object in the display list. } - setName = vi.fn((name: string) => { + setName = (name: string) => { this.name = name; - // return this.phaserSprite.setName(name); - }); + }; bringToTop(obj) { // Brings this Game Object to the top of its parents display list. @@ -207,5 +205,5 @@ export default class MockContainer implements MockGameObject { return this.list; } - disableInteractive = vi.fn(); + disableInteractive = () => null; } diff --git a/src/test/utils/mocks/mocksContainer/mockSprite.ts b/src/test/utils/mocks/mocksContainer/mockSprite.ts index ae43df46cf5..83ec3951151 100644 --- a/src/test/utils/mocks/mocksContainer/mockSprite.ts +++ b/src/test/utils/mocks/mocksContainer/mockSprite.ts @@ -1,6 +1,5 @@ import Phaser from "phaser"; import { MockGameObject } from "../mockGameObject"; -import { vi } from "vitest"; import Sprite = Phaser.GameObjects.Sprite; import Frame = Phaser.Textures.Frame; @@ -102,7 +101,7 @@ export default class MockSprite implements MockGameObject { return this.phaserSprite.stop(); } - setInteractive = vi.fn(); + setInteractive = () => null; on(event, callback, source) { return this.phaserSprite.on(event, callback, source); diff --git a/src/test/utils/mocks/mocksContainer/mockText.ts b/src/test/utils/mocks/mocksContainer/mockText.ts index 5a89432902b..5462056f1e5 100644 --- a/src/test/utils/mocks/mocksContainer/mockText.ts +++ b/src/test/utils/mocks/mocksContainer/mockText.ts @@ -1,5 +1,4 @@ import UI from "#app/ui/ui"; -import { vi } from "vitest"; import { MockGameObject } from "../mockGameObject"; export default class MockText implements MockGameObject { @@ -193,11 +192,11 @@ export default class MockText implements MockGameObject { }; } - setColor = vi.fn((color: string) => { + setColor = (color: string) => { this.color = color; - }); + }; - setInteractive = vi.fn(); + setInteractive = () => null; setShadowColor(color) { // Sets the shadow color. @@ -223,9 +222,9 @@ export default class MockText implements MockGameObject { // return this.phaserText.setAlpha(alpha); } - setName = vi.fn((name: string) => { + setName = (name: string) => { this.name = name; - }); + }; setAlign(align) { // return this.phaserText.setAlign(align);