From c2986891f6aac87cec98232735945af756e6643f Mon Sep 17 00:00:00 2001 From: Yusuke Sakurai Date: Fri, 7 Feb 2020 16:23:38 +0900 Subject: remove non-null assertion operator from std (part1) (#3900) --- std/testing/format.ts | 6 +++++- std/testing/mod.ts | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'std/testing') diff --git a/std/testing/format.ts b/std/testing/format.ts index 953347c27..62fdde5eb 100644 --- a/std/testing/format.ts +++ b/std/testing/format.ts @@ -1,3 +1,5 @@ +import { assert } from "./asserts.ts"; + // This file is ported from pretty-format@24.0.0 /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. @@ -361,7 +363,9 @@ const getKeysOfEnumerableProperties = (object: {}): Array => { if (Object.getOwnPropertySymbols) { Object.getOwnPropertySymbols(object).forEach((symbol): void => { - if (Object.getOwnPropertyDescriptor(object, symbol)!.enumerable) { + const d = Object.getOwnPropertyDescriptor(object, symbol); + assert(d != null); + if (d.enumerable) { keys.push(symbol); } }); diff --git a/std/testing/mod.ts b/std/testing/mod.ts index 16eae5ebe..a60e9c93f 100644 --- a/std/testing/mod.ts +++ b/std/testing/mod.ts @@ -261,11 +261,14 @@ function printResults( } function previousPrinted(name: string, results: TestResults): boolean { - const curIndex: number = results.keys.get(name)!; + const curIndex = results.keys.get(name); + assert(curIndex != null); if (curIndex === 0) { return true; } - return results.cases.get(curIndex - 1)!.printed; + const prev = results.cases.get(curIndex - 1); + assert(prev != null); + return prev.printed; } async function createTestCase( @@ -274,7 +277,10 @@ async function createTestCase( exitOnFail: boolean, { fn, name }: TestDefinition ): Promise { - const result: TestResult = results.cases.get(results.keys.get(name)!)!; + const i = results.keys.get(name); + assert(i != null); + const result = results.cases.get(i); + assert(result != null); try { const start = performance.now(); await fn(); -- cgit v1.2.3