Skip to content

Commit 800ffa3

Browse files
committed
fix: reset state on tests, move class init to BeforeEach instead of BeforeAll
1 parent 204c12e commit 800ffa3

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

tests/functional/authorization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("Authorization", () => {
2121
let schema: GraphQLSchema;
2222
let sampleResolver: any;
2323

24-
beforeAll(async () => {
24+
beforeEach(async () => {
2525
getMetadataStorage().clear();
2626

2727
@ObjectType()
@@ -608,7 +608,7 @@ describe("Authorization", () => {
608608
describe("with constant readonly array or roles", () => {
609609
let testResolver: Function;
610610

611-
beforeAll(() => {
611+
beforeEach(() => {
612612
getMetadataStorage().clear();
613613

614614
const CONSTANT_ROLES = ["a", "b", "c"] as const;

tests/functional/middlewares.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ describe("Middlewares", () => {
282282

283283
// clear ResolverMiddlewareMetadata for other tests
284284
getMetadataStorage().resolverMiddlewares = [];
285+
getMetadataStorage().resolverMiddlewaresByTargetCache = new Map();
286+
getMetadataStorage().middlewaresByTargetAndFieldCache = new Map();
285287

286288
const query = `query {
287289
middlewareOrderQuery

tests/functional/validation.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,13 @@ describe("Custom validation", () => {
679679
let validateResolverData: ResolverData[] = [];
680680
let sampleQueryArgs: any[] = [];
681681

682-
beforeAll(async () => {
682+
beforeEach(() => {
683+
// Reset ALL shared state
683684
getMetadataStorage().clear();
685+
validateArgs = [];
686+
validateTypes = [];
687+
validateResolverData = [];
688+
sampleQueryArgs = [];
684689

685690
@ArgsType()
686691
class SampleArgs {
@@ -725,13 +730,6 @@ describe("Custom validation", () => {
725730
sampleResolverCls = SampleResolver;
726731
});
727732

728-
beforeEach(() => {
729-
validateArgs = [];
730-
validateTypes = [];
731-
validateResolverData = [];
732-
sampleQueryArgs = [];
733-
});
734-
735733
it("should call `validateFn` function provided in option with proper params", async () => {
736734
schema = await buildSchema({
737735
resolvers: [sampleResolverCls],

0 commit comments

Comments
 (0)