Replace vi.fn() with () => null whenenver possible (#4182)

This commit is contained in:
NightKev 2024-09-11 13:54:42 -07:00 committed by GitHub
parent 89dac46dfc
commit ce9a75f074
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 18 additions and 24 deletions

View File

@ -41,7 +41,7 @@ window.URL.createObjectURL = (blob: Blob) => {
}); });
return null; return null;
}; };
navigator.getGamepads = vi.fn().mockReturnValue([]); navigator.getGamepads = () => [];
global.fetch = vi.fn(MockFetch); global.fetch = vi.fn(MockFetch);
Utils.setCookie(Utils.sessionIdKey, 'fake_token'); Utils.setCookie(Utils.sessionIdKey, 'fake_token');

View File

@ -1,4 +1,3 @@
import { vi } from "vitest";
import MockGraphics from "./mocksContainer/mockGraphics"; import MockGraphics from "./mocksContainer/mockGraphics";
import MockTextureManager from "./mockTextureManager"; import MockTextureManager from "./mockTextureManager";
@ -16,8 +15,8 @@ export class MockGameObjectCreator {
rexTransitionImagePack() { rexTransitionImagePack() {
return { return {
transit: vi.fn(), transit: () => null,
once: vi.fn(), once: () => null,
}; };
} }
} }

View File

@ -1,13 +1,12 @@
import { vi } from "vitest";
import { MockGameObject } from "./mockGameObject"; import { MockGameObject } from "./mockGameObject";
/** Mocks video-related stuff */ /** Mocks video-related stuff */
export class MockVideoGameObject implements MockGameObject { export class MockVideoGameObject implements MockGameObject {
constructor() {} constructor() {}
public play = vi.fn(); public play = () => null;
public stop = vi.fn(() => this); public stop = () => this;
public setOrigin = vi.fn(); public setOrigin = () => null;
public setScale = vi.fn(); public setScale = () => null;
public setVisible = vi.fn(); public setVisible = () => null;
} }

View File

@ -1,5 +1,4 @@
import MockTextureManager from "#test/utils/mocks/mockTextureManager"; import MockTextureManager from "#test/utils/mocks/mockTextureManager";
import { vi } from "vitest";
import { MockGameObject } from "../mockGameObject"; import { MockGameObject } from "../mockGameObject";
export default class MockContainer implements 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. /// 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) { setOrigin(x, y) {
this.x = x; 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. // 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; this.name = name;
// return this.phaserSprite.setName(name); };
});
bringToTop(obj) { bringToTop(obj) {
// Brings this Game Object to the top of its parents display list. // 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; return this.list;
} }
disableInteractive = vi.fn(); disableInteractive = () => null;
} }

View File

@ -1,6 +1,5 @@
import Phaser from "phaser"; import Phaser from "phaser";
import { MockGameObject } from "../mockGameObject"; import { MockGameObject } from "../mockGameObject";
import { vi } from "vitest";
import Sprite = Phaser.GameObjects.Sprite; import Sprite = Phaser.GameObjects.Sprite;
import Frame = Phaser.Textures.Frame; import Frame = Phaser.Textures.Frame;
@ -102,7 +101,7 @@ export default class MockSprite implements MockGameObject {
return this.phaserSprite.stop(); return this.phaserSprite.stop();
} }
setInteractive = vi.fn(); setInteractive = () => null;
on(event, callback, source) { on(event, callback, source) {
return this.phaserSprite.on(event, callback, source); return this.phaserSprite.on(event, callback, source);

View File

@ -1,5 +1,4 @@
import UI from "#app/ui/ui"; import UI from "#app/ui/ui";
import { vi } from "vitest";
import { MockGameObject } from "../mockGameObject"; import { MockGameObject } from "../mockGameObject";
export default class MockText implements 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; this.color = color;
}); };
setInteractive = vi.fn(); setInteractive = () => null;
setShadowColor(color) { setShadowColor(color) {
// Sets the shadow color. // Sets the shadow color.
@ -223,9 +222,9 @@ export default class MockText implements MockGameObject {
// return this.phaserText.setAlpha(alpha); // return this.phaserText.setAlpha(alpha);
} }
setName = vi.fn((name: string) => { setName = (name: string) => {
this.name = name; this.name = name;
}); };
setAlign(align) { setAlign(align) {
// return this.phaserText.setAlign(align); // return this.phaserText.setAlign(align);