From 58858b5078932ce9bf8c3efa4e9c90a6d19673c7 Mon Sep 17 00:00:00 2001 From: Bethany Date: Wed, 9 Aug 2023 17:48:53 -0700 Subject: [PATCH] don't use non-null assertions --- packages/artifact/__tests__/retention.test.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/artifact/__tests__/retention.test.ts b/packages/artifact/__tests__/retention.test.ts index 898c52a0..83de5342 100644 --- a/packages/artifact/__tests__/retention.test.ts +++ b/packages/artifact/__tests__/retention.test.ts @@ -14,11 +14,13 @@ describe('retention', () => { const exp = retention.getExpiration(30) expect(exp).toBeDefined() - const expDate = Timestamp.toDate(exp!) // we check whether exp is defined above - const expected = new Date() - expected.setDate(expected.getDate() + 30) + if (exp) { + const expDate = Timestamp.toDate(exp) + const expected = new Date() + expected.setDate(expected.getDate() + 30) - expect(expDate).toEqual(expected) + expect(expDate).toEqual(expected) + } }) it('should return the max retention days if the inputted retention days is greater than the max retention days', () => { @@ -30,11 +32,13 @@ describe('retention', () => { const exp = retention.getExpiration(120) expect(exp).toBeDefined() - const expDate = Timestamp.toDate(exp!) // we check whether exp is defined above - const expected = new Date() - expected.setDate(expected.getDate() + 90) + if (exp) { + const expDate = Timestamp.toDate(exp) // we check whether exp is defined above + const expected = new Date() + expected.setDate(expected.getDate() + 90) - expect(expDate).toEqual(expected) + expect(expDate).toEqual(expected) + } }) it('should return undefined if the inputted retention days is undefined', () => { @@ -50,10 +54,12 @@ describe('retention', () => { const exp = retention.getExpiration(30) expect(exp).toBeDefined() - const expDate = Timestamp.toDate(exp!) // we check whether exp is defined above - const expected = new Date() - expected.setDate(expected.getDate() + 30) + if (exp) { + const expDate = Timestamp.toDate(exp) // we check whether exp is defined above + const expected = new Date() + expected.setDate(expected.getDate() + 30) - expect(expDate).toEqual(expected) + expect(expDate).toEqual(expected) + } }) })