refactor: fix typescript strict flag failures in all tests (#30993)

Fixes all TypeScript failures caused by enabling the `--strict`
flag for test source files. We also want to enable the strict
options for tests as the strictness enforcement improves the
overall codehealth, unveiled common issues and additionally it
allows us to enable `strict` in the `tsconfig.json` that is picked
up by IDE's.

PR Close #30993
This commit is contained in:
Paul Gschwendtner
2019-06-14 12:19:09 +02:00
committed by Miško Hevery
parent 69a612d402
commit 647d7bdd88
38 changed files with 256 additions and 203 deletions

View File

@ -244,7 +244,7 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils', () => {
});
it('should work on templates', () => {
const templateComment = Array.from(fixture.nativeElement.childNodes)
const templateComment = Array.from((fixture.nativeElement as HTMLElement).childNodes)
.find((node: ChildNode) => node.nodeType === Node.COMMENT_NODE) !;
const lContext = loadLContext(templateComment);
expect(lContext).toBeDefined();
@ -252,7 +252,7 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils', () => {
});
it('should work on ng-container', () => {
const ngContainerComment = Array.from(fixture.nativeElement.childNodes)
const ngContainerComment = Array.from((fixture.nativeElement as HTMLElement).childNodes)
.find(
(node: ChildNode) => node.nodeType === Node.COMMENT_NODE &&
node.textContent === `ng-container`) !;

View File

@ -42,8 +42,9 @@ describe('property interpolation', () => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
const titles = Array.from(fixture.nativeElement.querySelectorAll('div[title]'))
.map((div: HTMLDivElement) => div.title);
const titles =
Array.from(<NodeListOf<HTMLDivElement>>fixture.nativeElement.querySelectorAll('div[title]'))
.map((div: HTMLDivElement) => div.title);
expect(titles).toEqual([
'a1b2c3d4e5f6g7h8i9j',
@ -194,7 +195,9 @@ describe('property interpolation', () => {
const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();
const titles = Array.from(fixture.nativeElement.querySelectorAll('img[title]'))
const titles = Array
.from(<NodeListOf<HTMLImageElement>>fixture.nativeElement.querySelectorAll(
'img[title]'))
.map((img: HTMLImageElement) => img.title);
expect(titles).toEqual([
@ -210,8 +213,9 @@ describe('property interpolation', () => {
'1',
]);
const others = Array.from(fixture.nativeElement.querySelectorAll('img[alt]'))
.map((img: HTMLImageElement) => img.alt);
const others =
Array.from(<NodeListOf<HTMLImageElement>>fixture.nativeElement.querySelectorAll('img[alt]'))
.map((img: HTMLImageElement) => img.alt);
expect(others).toEqual([
'a1b2c3d4e5f6g7h8i9j',

View File

@ -182,8 +182,8 @@ function getRendererFactory2(document: any): RendererFactory2 {
const rendererFactory = new ServerRendererFactory2(
eventManager, fakeNgZone, document, new ɵDomSharedStylesHost(document));
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function() {
const renderer = origCreateRenderer.apply(this, arguments);
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = origCreateRenderer.call(this, element, type);
renderer.destroyNode = () => {};
return renderer;
};

View File

@ -41,8 +41,9 @@ describe('text instructions', () => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
const allTextContent = Array.from(fixture.nativeElement.querySelectorAll('div'))
.map((div: HTMLDivElement) => div.textContent);
const allTextContent =
Array.from((fixture.nativeElement as HTMLElement).querySelectorAll('div'))
.map((div: HTMLDivElement) => div.textContent);
expect(allTextContent).toEqual([
'a1b2c3d4e5f6g7h8i9j',

View File

@ -7,7 +7,7 @@
*/
import {CommonModule, DOCUMENT} from '@angular/common';
import {Compiler, Component, ComponentFactoryResolver, Directive, DoCheck, ElementRef, EmbeddedViewRef, ErrorHandler, NO_ERRORS_SCHEMA, NgModule, OnInit, Pipe, PipeTransform, QueryList, RendererFactory2, Sanitizer, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, ɵi18nConfigureLocalize} from '@angular/core';
import {Compiler, Component, ComponentFactoryResolver, Directive, DoCheck, ElementRef, EmbeddedViewRef, ErrorHandler, NO_ERRORS_SCHEMA, NgModule, OnInit, Pipe, PipeTransform, QueryList, RendererFactory2, RendererType2, Sanitizer, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, ɵi18nConfigureLocalize} from '@angular/core';
import {Input} from '@angular/core/src/metadata';
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
import {TestBed, TestComponentRenderer} from '@angular/core/testing';
@ -541,8 +541,8 @@ describe('ViewContainerRef', () => {
const _origRendererFactory = TestBed.get(RendererFactory2) as RendererFactory2;
const _origCreateRenderer = _origRendererFactory.createRenderer;
_origRendererFactory.createRenderer = function() {
const renderer = _origCreateRenderer.apply(_origRendererFactory, arguments);
_origRendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = _origCreateRenderer.call(_origRendererFactory, element, type);
renderer.destroyNode = () => {};
return renderer;
};