From 443835ef8a8ab3d39c0b0e8f309c61d9072a8b9b Mon Sep 17 00:00:00 2001 From: Alena Khineika Date: Tue, 5 Mar 2024 15:42:24 +0100 Subject: [PATCH] test(NODE-5992): fix env var restoration in tests (#4017) --- test/integration/auth/mongodb_aws.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/integration/auth/mongodb_aws.test.ts b/test/integration/auth/mongodb_aws.test.ts index cc9e17881f..d3f6933c35 100644 --- a/test/integration/auth/mongodb_aws.test.ts +++ b/test/integration/auth/mongodb_aws.test.ts @@ -88,15 +88,17 @@ describe('MONGODB-AWS', function () { }); describe('with missing aws token', () => { - let awsSessionToken; + let awsSessionToken: string | undefined; - beforeEach(function () { + beforeEach(() => { awsSessionToken = process.env.AWS_SESSION_TOKEN; delete process.env.AWS_SESSION_TOKEN; }); - afterEach(async () => { - process.env.AWS_SESSION_TOKEN = awsSessionToken; + afterEach(() => { + if (awsSessionToken != null) { + process.env.AWS_SESSION_TOKEN = awsSessionToken; + } }); it('should not throw an exception when aws token is missing', async function () {