Tests: Moves class (re)resolution to beforeEach
to help ensure that all mocks have been reset.
This commit is contained in:
parent
71312c8ed7
commit
a7d3e0d59a
@ -19,10 +19,7 @@ describe("InsuranceController", () =>
|
|||||||
|
|
||||||
beforeEach(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
// (Re)resolve the test target.
|
|
||||||
insuranceController = container.resolve<InsuranceController>("InsuranceController");
|
insuranceController = container.resolve<InsuranceController>("InsuranceController");
|
||||||
|
|
||||||
// Reset the insurance fixture before each test.
|
|
||||||
insuranceFixture = new ProfileInsuranceFactory().adjustPackageDates().get();
|
insuranceFixture = new ProfileInsuranceFactory().adjustPackageDates().get();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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 { BotGenerator } from "@spt-aki/generators/BotGenerator";
|
||||||
import { BotGenerationDetails } from "@spt-aki/models/spt/bots/BotGenerationDetails";
|
|
||||||
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
||||||
|
|
||||||
describe("BotGenerator", () =>
|
describe("BotGenerator", () =>
|
||||||
{
|
{
|
||||||
let botGenerator: any;
|
let botGenerator: any;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
botGenerator = container.resolve<BotGenerator>("BotGenerator");
|
botGenerator = container.resolve<BotGenerator>("BotGenerator");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() =>
|
afterEach(() =>
|
||||||
{
|
{
|
||||||
|
// Restore all mocks to their original implementations.
|
||||||
|
vi.resetAllMocks();
|
||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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 { BotLevelGenerator } from "@spt-aki/generators/BotLevelGenerator";
|
||||||
import { MinMax } from "@spt-aki/models/common/MinMax";
|
import { MinMax } from "@spt-aki/models/common/MinMax";
|
||||||
@ -12,7 +12,7 @@ describe("BotLevelGenerator", () =>
|
|||||||
let botLevelGenerator: any;
|
let botLevelGenerator: any;
|
||||||
let databaseServer: DatabaseServer;
|
let databaseServer: DatabaseServer;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
botLevelGenerator = container.resolve<BotLevelGenerator>("BotLevelGenerator");
|
botLevelGenerator = container.resolve<BotLevelGenerator>("BotLevelGenerator");
|
||||||
databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
databaseServer = container.resolve<DatabaseServer>("DatabaseServer");
|
||||||
@ -81,4 +81,4 @@ describe("BotLevelGenerator", () =>
|
|||||||
expect(result).toBe(79);
|
expect(result).toBe(79);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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";
|
import { BotHelper } from "@spt-aki/helpers/BotHelper";
|
||||||
|
|
||||||
@ -8,7 +8,7 @@ describe("BotHelper", () =>
|
|||||||
{
|
{
|
||||||
let botHelper: any;
|
let botHelper: any;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
botHelper = container.resolve<BotHelper>("BotHelper");
|
botHelper = container.resolve<BotHelper>("BotHelper");
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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 { HandbookHelper } from "@spt-aki/helpers/HandbookHelper";
|
||||||
import { Money } from "@spt-aki/models/enums/Money";
|
import { Money } from "@spt-aki/models/enums/Money";
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ describe("HandbookHelper", () =>
|
|||||||
{
|
{
|
||||||
let handbookHelper: any;
|
let handbookHelper: any;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
handbookHelper = container.resolve<HandbookHelper>("HandbookHelper");
|
handbookHelper = container.resolve<HandbookHelper>("HandbookHelper");
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import { InRaidHelper } from "@spt-aki/helpers/InRaidHelper";
|
|
||||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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", () =>
|
describe("InRaidHelper", () =>
|
||||||
{
|
{
|
||||||
let inraidHelper: any;
|
let inraidHelper: any;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
inraidHelper = container.resolve<InRaidHelper>("InRaidHelper");
|
inraidHelper = container.resolve<InRaidHelper>("InRaidHelper");
|
||||||
});
|
});
|
||||||
@ -113,4 +114,4 @@ describe("InRaidHelper", () =>
|
|||||||
expect(result).toBe(0);
|
expect(result).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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 { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
||||||
import { Item, Repairable } from "@spt-aki/models/eft/common/tables/IItem";
|
import { Item, Repairable } from "@spt-aki/models/eft/common/tables/IItem";
|
||||||
@ -11,7 +11,7 @@ describe("ItemHelper", () =>
|
|||||||
{
|
{
|
||||||
let itemHelper: ItemHelper;
|
let itemHelper: ItemHelper;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
itemHelper = container.resolve<ItemHelper>("ItemHelper");
|
itemHelper = container.resolve<ItemHelper>("ItemHelper");
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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";
|
import { ItemBaseClassService } from "@spt-aki/services/ItemBaseClassService";
|
||||||
|
|
||||||
describe("ItemBaseClassService", () =>
|
describe("ItemBaseClassService", () =>
|
||||||
{
|
{
|
||||||
let itemBaseClassService: any;
|
let itemBaseClassService: any;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
itemBaseClassService = container.resolve<ItemBaseClassService>("ItemBaseClassService");
|
itemBaseClassService = container.resolve<ItemBaseClassService>("ItemBaseClassService");
|
||||||
});
|
});
|
||||||
@ -73,9 +73,9 @@ describe("ItemBaseClassService", () =>
|
|||||||
{
|
{
|
||||||
// Set cache to false
|
// Set cache to false
|
||||||
itemBaseClassService.cacheGenerated = false;
|
itemBaseClassService.cacheGenerated = false;
|
||||||
|
|
||||||
const hydrateItemBaseClassCacheSpy = vi.spyOn(itemBaseClassService, "hydrateItemBaseClassCache");
|
const hydrateItemBaseClassCacheSpy = vi.spyOn(itemBaseClassService, "hydrateItemBaseClassCache");
|
||||||
|
|
||||||
// Remove item from base cache
|
// Remove item from base cache
|
||||||
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
const salewaTpl = "544fb45d4bdc2dee738b4568";
|
||||||
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
delete itemBaseClassService.itemBaseClassesCache[salewaTpl];
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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";
|
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.
|
let paymentService: any; // Using "any" to access private/protected methods without type errors.
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
paymentService = container.resolve<PaymentService>("PaymentService");
|
paymentService = container.resolve<PaymentService>("PaymentService");
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { container } from "tsyringe";
|
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 { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
||||||
import { PlayerService } from "@spt-aki/services/PlayerService";
|
import { PlayerService } from "@spt-aki/services/PlayerService";
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ describe("PlayerService", () =>
|
|||||||
{
|
{
|
||||||
let playerService: PlayerService;
|
let playerService: PlayerService;
|
||||||
|
|
||||||
beforeAll(() =>
|
beforeEach(() =>
|
||||||
{
|
{
|
||||||
playerService = container.resolve<PlayerService>("PlayerService");
|
playerService = container.resolve<PlayerService>("PlayerService");
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user