Tests: Moves class (re)resolution to beforeEach to help ensure that all mocks have been reset.

This commit is contained in:
Refringe 2023-11-06 14:39:12 -05:00
parent 71312c8ed7
commit a7d3e0d59a
No known key found for this signature in database
GPG Key ID: 64E03E5F892C6F9E
10 changed files with 29 additions and 28 deletions

View File

@ -19,10 +19,7 @@ describe("InsuranceController", () =>
beforeEach(() =>
{
// (Re)resolve the test target.
insuranceController = container.resolve<InsuranceController>("InsuranceController");
// Reset the insurance fixture before each test.
insuranceFixture = new ProfileInsuranceFactory().adjustPackageDates().get();
});

View File

@ -1,22 +1,23 @@
/* eslint-disable @typescript-eslint/naming-convention */
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { BotGenerator } from "@spt-aki/generators/BotGenerator";
import { BotGenerationDetails } from "@spt-aki/models/spt/bots/BotGenerationDetails";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
describe("BotGenerator", () =>
{
let botGenerator: any;
beforeAll(() =>
beforeEach(() =>
{
botGenerator = container.resolve<BotGenerator>("BotGenerator");
});
afterEach(() =>
{
// Restore all mocks to their original implementations.
vi.resetAllMocks();
vi.restoreAllMocks();
});

View File

@ -1,6 +1,6 @@
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { BotLevelGenerator } from "@spt-aki/generators/BotLevelGenerator";
import { MinMax } from "@spt-aki/models/common/MinMax";
@ -12,7 +12,7 @@ describe("BotLevelGenerator", () =>
let botLevelGenerator: any;
let databaseServer: DatabaseServer;
beforeAll(() =>
beforeEach(() =>
{
botLevelGenerator = container.resolve<BotLevelGenerator>("BotLevelGenerator");
databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
@ -81,4 +81,4 @@ describe("BotLevelGenerator", () =>
expect(result).toBe(79);
});
});
});
});

View File

@ -1,6 +1,6 @@
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { BotHelper } from "@spt-aki/helpers/BotHelper";
@ -8,7 +8,7 @@ describe("BotHelper", () =>
{
let botHelper: any;
beforeAll(() =>
beforeEach(() =>
{
botHelper = container.resolve<BotHelper>("BotHelper");
});

View File

@ -1,6 +1,7 @@
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { HandbookHelper } from "@spt-aki/helpers/HandbookHelper";
import { Money } from "@spt-aki/models/enums/Money";
@ -8,7 +9,7 @@ describe("HandbookHelper", () =>
{
let handbookHelper: any;
beforeAll(() =>
beforeEach(() =>
{
handbookHelper = container.resolve<HandbookHelper>("HandbookHelper");
});

View File

@ -1,14 +1,15 @@
import { InRaidHelper } from "@spt-aki/helpers/InRaidHelper";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { InRaidHelper } from "@spt-aki/helpers/InRaidHelper";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
describe("InRaidHelper", () =>
{
let inraidHelper: any;
beforeAll(() =>
beforeEach(() =>
{
inraidHelper = container.resolve<InRaidHelper>("InRaidHelper");
});
@ -113,4 +114,4 @@ describe("InRaidHelper", () =>
expect(result).toBe(0);
});
});
});
});

View File

@ -1,6 +1,6 @@
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
import { Item, Repairable } from "@spt-aki/models/eft/common/tables/IItem";
@ -11,7 +11,7 @@ describe("ItemHelper", () =>
{
let itemHelper: ItemHelper;
beforeAll(() =>
beforeEach(() =>
{
itemHelper = container.resolve<ItemHelper>("ItemHelper");
});

View File

@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/naming-convention */
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { ItemBaseClassService } from "@spt-aki/services/ItemBaseClassService";
describe("ItemBaseClassService", () =>
{
let itemBaseClassService: any;
beforeAll(() =>
beforeEach(() =>
{
itemBaseClassService = container.resolve<ItemBaseClassService>("ItemBaseClassService");
});
@ -73,9 +73,9 @@ describe("ItemBaseClassService", () =>
{
// Set cache to false
itemBaseClassService.cacheGenerated = false;
const hydrateItemBaseClassCacheSpy = vi.spyOn(itemBaseClassService, "hydrateItemBaseClassCache");
// Remove item from base cache
const salewaTpl = "544fb45d4bdc2dee738b4568";
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { PaymentService } from "@spt-aki/services/PaymentService";
@ -16,7 +16,7 @@ describe("PaymentService", () =>
{
let paymentService: any; // Using "any" to access private/protected methods without type errors.
beforeAll(() =>
beforeEach(() =>
{
paymentService = container.resolve<PaymentService>("PaymentService");
});

View File

@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
import "reflect-metadata";
import { container } from "tsyringe";
import { vi, beforeAll, afterEach, describe, expect, it } from "vitest";
import { vi, beforeEach, afterEach, describe, expect, it } from "vitest";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { PlayerService } from "@spt-aki/services/PlayerService";
@ -9,7 +10,7 @@ describe("PlayerService", () =>
{
let playerService: PlayerService;
beforeAll(() =>
beforeEach(() =>
{
playerService = container.resolve<PlayerService>("PlayerService");
});