refactor(core): ensure compatibility with typescript strict flag (#30993)
As part of FW-1265, the `@angular/core` package is made compatible with the TypeScript `--strict` flag. This already unveiled a few bugs, so the strictness flag seems to help with increasing the overall code health. Read more about the strict flag [here](https://www.typescriptlang.org/docs/handbook/compiler-options.html) PR Close #30993
This commit is contained in:

committed by
Miško Hevery

parent
78e7fdd98d
commit
2200884e55
@ -39,6 +39,8 @@ const globalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
|
||||
const testBed = getTestBed();
|
||||
|
||||
export type TestFn = ((done: DoneFn) => any) | (() => any);
|
||||
|
||||
/**
|
||||
* Mechanism to run `beforeEach()` functions of Angular tests.
|
||||
*
|
||||
@ -112,8 +114,7 @@ export function beforeEachProviders(fn: Function): void {
|
||||
}
|
||||
|
||||
|
||||
function _it(
|
||||
jsmFn: Function, testName: string, testFn: (done?: DoneFn) => any, testTimeout = 0): void {
|
||||
function _it(jsmFn: Function, testName: string, testFn: TestFn, testTimeout = 0): void {
|
||||
if (runnerStack.length == 0) {
|
||||
// This left here intentionally, as we should never get here, and it aids debugging.
|
||||
// tslint:disable-next-line
|
||||
@ -135,7 +136,9 @@ function _it(
|
||||
runner.run();
|
||||
|
||||
if (testFn.length === 0) {
|
||||
const retVal = testFn();
|
||||
// TypeScript doesn't infer the TestFn type without parameters here, so we
|
||||
// need to manually cast it.
|
||||
const retVal = (testFn as() => any)();
|
||||
if (isPromise(retVal)) {
|
||||
// Asynchronous test function that returns a Promise - wait for completion.
|
||||
retVal.then(done, done.fail);
|
||||
@ -150,15 +153,15 @@ function _it(
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
export function it(expectation: string, assertion: (done: DoneFn) => any, timeout?: number): void {
|
||||
export function it(expectation: string, assertion: TestFn, timeout?: number): void {
|
||||
return _it(jsmIt, expectation, assertion, timeout);
|
||||
}
|
||||
|
||||
export function fit(expectation: string, assertion: (done: DoneFn) => any, timeout?: number): void {
|
||||
export function fit(expectation: string, assertion: TestFn, timeout?: number): void {
|
||||
return _it(jsmFIt, expectation, assertion, timeout);
|
||||
}
|
||||
|
||||
export function xit(expectation: string, assertion: (done: DoneFn) => any, timeout?: number): void {
|
||||
export function xit(expectation: string, assertion: TestFn, timeout?: number): void {
|
||||
return _it(jsmXIt, expectation, assertion, timeout);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user