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:
parent
69a612d402
commit
647d7bdd88
@ -67,7 +67,7 @@ class ReentrantInterceptor implements HttpInterceptor {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('initializes HttpClient properly', done => {
|
it('initializes HttpClient properly', done => {
|
||||||
injector.get(HttpClient).get('/test', {responseType: 'text'}).subscribe(value => {
|
injector.get(HttpClient).get('/test', {responseType: 'text'}).subscribe((value: string) => {
|
||||||
expect(value).toBe('ok!');
|
expect(value).toBe('ok!');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -76,7 +76,7 @@ class ReentrantInterceptor implements HttpInterceptor {
|
|||||||
it('intercepts outbound responses in the order in which interceptors were bound', done => {
|
it('intercepts outbound responses in the order in which interceptors were bound', done => {
|
||||||
injector.get(HttpClient)
|
injector.get(HttpClient)
|
||||||
.get('/test', {observe: 'response', responseType: 'text'})
|
.get('/test', {observe: 'response', responseType: 'text'})
|
||||||
.subscribe(value => done());
|
.subscribe(() => done());
|
||||||
const req = injector.get(HttpTestingController).expectOne('/test') as TestRequest;
|
const req = injector.get(HttpTestingController).expectOne('/test') as TestRequest;
|
||||||
expect(req.request.headers.get('Intercepted')).toEqual('A,B');
|
expect(req.request.headers.get('Intercepted')).toEqual('A,B');
|
||||||
req.flush('ok!');
|
req.flush('ok!');
|
||||||
@ -84,7 +84,7 @@ class ReentrantInterceptor implements HttpInterceptor {
|
|||||||
it('intercepts inbound responses in the right (reverse binding) order', done => {
|
it('intercepts inbound responses in the right (reverse binding) order', done => {
|
||||||
injector.get(HttpClient)
|
injector.get(HttpClient)
|
||||||
.get('/test', {observe: 'response', responseType: 'text'})
|
.get('/test', {observe: 'response', responseType: 'text'})
|
||||||
.subscribe(value => {
|
.subscribe((value: HttpResponse<string>) => {
|
||||||
expect(value.headers.get('Intercepted')).toEqual('B,A');
|
expect(value.headers.get('Intercepted')).toEqual('B,A');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -149,7 +149,10 @@ describe('defaultComparator', () => {
|
|||||||
expect(values.sort(defaultComparator)).toEqual([{key: false, value: 1}, {key: true, value: 3}]);
|
expect(values.sort(defaultComparator)).toEqual([{key: false, value: 1}, {key: true, value: 3}]);
|
||||||
});
|
});
|
||||||
it('should sort numbers as strings in numerical ascending', () => {
|
it('should sort numbers as strings in numerical ascending', () => {
|
||||||
const values = [{key: '2', value: 1}, {key: 1, value: 3}];
|
// We need to cast the values array to "any[]" because the object keys
|
||||||
|
// have no type overlap and the "Array.sort" expects all keys to have the
|
||||||
|
// same type when passed to the sort comparator.
|
||||||
|
const values = [{key: '2', value: 1}, {key: 1, value: 3}] as any[];
|
||||||
expect(values.sort(defaultComparator)).toEqual([{key: 1, value: 3}, {key: '2', value: 1}]);
|
expect(values.sort(defaultComparator)).toEqual([{key: 1, value: 3}, {key: '2', value: 1}]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -31,15 +31,14 @@ const EXTRACT_GENERATED_TRANSLATIONS_REGEXP =
|
|||||||
const diff = (a: Set<string>, b: Set<string>): Set<string> =>
|
const diff = (a: Set<string>, b: Set<string>): Set<string> =>
|
||||||
new Set([...Array.from(a)].filter(x => !b.has(x)));
|
new Set([...Array.from(a)].filter(x => !b.has(x)));
|
||||||
|
|
||||||
const extract =
|
const extract = (from: string, regex: any, transformFn: (match: any[], state: Set<any>) => any) => {
|
||||||
(from: string, regex: any, transformFn: (match: any[], state?: Set<any>) => any) => {
|
|
||||||
const result = new Set<any>();
|
const result = new Set<any>();
|
||||||
let item;
|
let item;
|
||||||
while ((item = regex.exec(from)) !== null) {
|
while ((item = regex.exec(from)) !== null) {
|
||||||
result.add(transformFn(item, result));
|
result.add(transformFn(item, result));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
// verify that we extracted all the necessary translations
|
// verify that we extracted all the necessary translations
|
||||||
// and their ids match the ones extracted via 'ng xi18n'
|
// and their ids match the ones extracted via 'ng xi18n'
|
||||||
|
@ -10,6 +10,7 @@ import * as ng from '@angular/compiler-cli';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as ts from 'typescript';
|
||||||
import {TestSupport, expectNoDiagnostics, setup} from '../test_support';
|
import {TestSupport, expectNoDiagnostics, setup} from '../test_support';
|
||||||
|
|
||||||
type MockFiles = {
|
type MockFiles = {
|
||||||
@ -52,7 +53,7 @@ describe('ng type checker', () => {
|
|||||||
if (!diagnostics || !diagnostics.length) {
|
if (!diagnostics || !diagnostics.length) {
|
||||||
throw new Error('Expected a diagnostic error message');
|
throw new Error('Expected a diagnostic error message');
|
||||||
} else {
|
} else {
|
||||||
const matches: (d: ng.Diagnostic) => boolean = typeof message === 'string' ?
|
const matches: (d: ng.Diagnostic | ts.Diagnostic) => boolean = typeof message === 'string' ?
|
||||||
d => ng.isNgDiagnostic(d)&& d.messageText == message :
|
d => ng.isNgDiagnostic(d)&& d.messageText == message :
|
||||||
d => ng.isNgDiagnostic(d) && message.test(d.messageText);
|
d => ng.isNgDiagnostic(d) && message.test(d.messageText);
|
||||||
const matchingDiagnostics = diagnostics.filter(matches) as ng.Diagnostic[];
|
const matchingDiagnostics = diagnostics.filter(matches) as ng.Diagnostic[];
|
||||||
|
@ -11,7 +11,7 @@ import * as ts from 'typescript';
|
|||||||
|
|
||||||
import {CompilerHostAdapter, MetadataBundler, MetadataBundlerHost} from '../../src/metadata/bundler';
|
import {CompilerHostAdapter, MetadataBundler, MetadataBundlerHost} from '../../src/metadata/bundler';
|
||||||
import {MetadataCollector} from '../../src/metadata/collector';
|
import {MetadataCollector} from '../../src/metadata/collector';
|
||||||
import {ClassMetadata, MetadataGlobalReferenceExpression, ModuleMetadata} from '../../src/metadata/schema';
|
import {ClassMetadata, MetadataEntry, MetadataGlobalReferenceExpression, ModuleMetadata} from '../../src/metadata/schema';
|
||||||
import {Directory, MockAotContext, MockCompilerHost} from '../mocks';
|
import {Directory, MockAotContext, MockCompilerHost} from '../mocks';
|
||||||
|
|
||||||
describe('compiler host adapter', () => {
|
describe('compiler host adapter', () => {
|
||||||
@ -242,7 +242,7 @@ describe('metadata bundler', () => {
|
|||||||
const deepIndexMetadata = host.getMetadataFor('/lib/deep/index') !;
|
const deepIndexMetadata = host.getMetadataFor('/lib/deep/index') !;
|
||||||
|
|
||||||
// The unbundled metadata should reference symbols using the relative module path.
|
// The unbundled metadata should reference symbols using the relative module path.
|
||||||
expect(deepIndexMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining({
|
expect(deepIndexMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining<MetadataEntry>({
|
||||||
statics: {
|
statics: {
|
||||||
ngInjectableDef: {
|
ngInjectableDef: {
|
||||||
__symbolic: 'call',
|
__symbolic: 'call',
|
||||||
@ -258,7 +258,7 @@ describe('metadata bundler', () => {
|
|||||||
// For the bundled metadata, the "sharedFn" symbol should not be referenced using the
|
// For the bundled metadata, the "sharedFn" symbol should not be referenced using the
|
||||||
// relative module path (like for unbundled), because the metadata bundle can be stored
|
// relative module path (like for unbundled), because the metadata bundle can be stored
|
||||||
// anywhere and it's not guaranteed that the relatively referenced files are present.
|
// anywhere and it's not guaranteed that the relatively referenced files are present.
|
||||||
expect(bundledMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining({
|
expect(bundledMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining<MetadataEntry>({
|
||||||
statics: {
|
statics: {
|
||||||
ngInjectableDef: {
|
ngInjectableDef: {
|
||||||
__symbolic: 'call',
|
__symbolic: 'call',
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
import {AbsoluteFsPath, resolve} from '@angular/compiler-cli/src/ngtsc/file_system';
|
import {AbsoluteFsPath, resolve} from '@angular/compiler-cli/src/ngtsc/file_system';
|
||||||
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
|
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
|
||||||
import {AbsoluteSourceSpan, IdentifierKind, TopLevelIdentifier} from '@angular/compiler-cli/src/ngtsc/indexer';
|
import {AbsoluteSourceSpan, IdentifierKind, IndexedComponent, TopLevelIdentifier} from '@angular/compiler-cli/src/ngtsc/indexer';
|
||||||
import {ParseSourceFile} from '@angular/compiler/src/compiler';
|
import {ParseSourceFile} from '@angular/compiler/src/compiler';
|
||||||
|
|
||||||
import {NgtscTestEnvironment} from './env';
|
import {NgtscTestEnvironment} from './env';
|
||||||
@ -43,7 +43,7 @@ runInEachFileSystem(() => {
|
|||||||
const [[decl, indexedComp]] = Array.from(indexed.entries());
|
const [[decl, indexedComp]] = Array.from(indexed.entries());
|
||||||
|
|
||||||
expect(decl.getText()).toContain('export class TestCmp {}');
|
expect(decl.getText()).toContain('export class TestCmp {}');
|
||||||
expect(indexedComp).toEqual(jasmine.objectContaining({
|
expect(indexedComp).toEqual(jasmine.objectContaining<IndexedComponent>({
|
||||||
name: 'TestCmp',
|
name: 'TestCmp',
|
||||||
selector: 'test-cmp',
|
selector: 'test-cmp',
|
||||||
file: new ParseSourceFile(componentContent, testSourceFile),
|
file: new ParseSourceFile(componentContent, testSourceFile),
|
||||||
|
@ -83,8 +83,10 @@ describe('ng program', () => {
|
|||||||
|
|
||||||
const originalGetSourceFile = host.getSourceFile;
|
const originalGetSourceFile = host.getSourceFile;
|
||||||
const cache = new Map<string, ts.SourceFile>();
|
const cache = new Map<string, ts.SourceFile>();
|
||||||
host.getSourceFile = function(fileName: string): ts.SourceFile {
|
host.getSourceFile = function(
|
||||||
const sf = originalGetSourceFile.call(host, fileName) as ts.SourceFile;
|
fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile |
|
||||||
|
undefined {
|
||||||
|
const sf = originalGetSourceFile.call(host, fileName, languageVersion);
|
||||||
if (sf) {
|
if (sf) {
|
||||||
if (cache.has(sf.fileName)) {
|
if (cache.has(sf.fileName)) {
|
||||||
const oldSf = cache.get(sf.fileName) !;
|
const oldSf = cache.get(sf.fileName) !;
|
||||||
@ -196,12 +198,14 @@ describe('ng program', () => {
|
|||||||
const host = ng.createCompilerHost({options});
|
const host = ng.createCompilerHost({options});
|
||||||
const originalGetSourceFile = host.getSourceFile;
|
const originalGetSourceFile = host.getSourceFile;
|
||||||
const fileCache = new Map<string, ts.SourceFile>();
|
const fileCache = new Map<string, ts.SourceFile>();
|
||||||
host.getSourceFile = (fileName: string) => {
|
host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget) => {
|
||||||
if (fileCache.has(fileName)) {
|
if (fileCache.has(fileName)) {
|
||||||
return fileCache.get(fileName);
|
return fileCache.get(fileName);
|
||||||
}
|
}
|
||||||
const sf = originalGetSourceFile.call(host, fileName);
|
const sf = originalGetSourceFile.call(host, fileName, languageVersion);
|
||||||
|
if (sf !== undefined) {
|
||||||
fileCache.set(fileName, sf);
|
fileCache.set(fileName, sf);
|
||||||
|
}
|
||||||
return sf;
|
return sf;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -469,8 +473,8 @@ describe('ng program', () => {
|
|||||||
|
|
||||||
host.writeFile =
|
host.writeFile =
|
||||||
(fileName: string, data: string, writeByteOrderMark: boolean,
|
(fileName: string, data: string, writeByteOrderMark: boolean,
|
||||||
onError: (message: string) => void|undefined,
|
onError: ((message: string) => void) | undefined,
|
||||||
sourceFiles: ReadonlyArray<ts.SourceFile>) => {
|
sourceFiles?: ReadonlyArray<ts.SourceFile>) => {
|
||||||
written.set(fileName, {original: sourceFiles, data});
|
written.set(fileName, {original: sourceFiles, data});
|
||||||
};
|
};
|
||||||
const program = ng.createProgram(
|
const program = ng.createProgram(
|
||||||
@ -1095,9 +1099,9 @@ describe('ng program', () => {
|
|||||||
});
|
});
|
||||||
const host = ng.createCompilerHost({options});
|
const host = ng.createCompilerHost({options});
|
||||||
const originalGetSourceFile = host.getSourceFile;
|
const originalGetSourceFile = host.getSourceFile;
|
||||||
host.getSourceFile =
|
host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget,
|
||||||
(fileName: string, languageVersion: ts.ScriptTarget,
|
onError?: ((message: string) => void) | undefined): ts.SourceFile |
|
||||||
onError?: ((message: string) => void) | undefined): ts.SourceFile => {
|
undefined => {
|
||||||
// We should never try to load .ngfactory.ts files
|
// We should never try to load .ngfactory.ts files
|
||||||
if (fileName.match(/\.ngfactory\.ts$/)) {
|
if (fileName.match(/\.ngfactory\.ts$/)) {
|
||||||
throw new Error(`Non existent ngfactory file: ` + fileName);
|
throw new Error(`Non existent ngfactory file: ` + fileName);
|
||||||
|
@ -20,7 +20,8 @@ describe('StaticReflector', () => {
|
|||||||
function init(
|
function init(
|
||||||
testData: {[key: string]: any} = DEFAULT_TEST_DATA,
|
testData: {[key: string]: any} = DEFAULT_TEST_DATA,
|
||||||
decorators: {name: string, filePath: string, ctor: any}[] = [],
|
decorators: {name: string, filePath: string, ctor: any}[] = [],
|
||||||
errorRecorder?: (error: any, fileName: string) => void, collectorOptions?: CollectorOptions) {
|
errorRecorder?: (error: any, fileName?: string) => void,
|
||||||
|
collectorOptions?: CollectorOptions) {
|
||||||
const symbolCache = new StaticSymbolCache();
|
const symbolCache = new StaticSymbolCache();
|
||||||
host = new MockStaticSymbolResolverHost(testData, collectorOptions);
|
host = new MockStaticSymbolResolverHost(testData, collectorOptions);
|
||||||
const summaryResolver = new MockSummaryResolver([]);
|
const summaryResolver = new MockSummaryResolver([]);
|
||||||
@ -618,7 +619,7 @@ describe('StaticReflector', () => {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
let error: any = undefined;
|
let error: any = undefined;
|
||||||
init(data, [], (err: any, filePath: string) => {
|
init(data, [], (err: any, filePath?: string) => {
|
||||||
expect(error).toBeUndefined();
|
expect(error).toBeUndefined();
|
||||||
error = err;
|
error = err;
|
||||||
});
|
});
|
||||||
|
@ -70,8 +70,7 @@ import {escapeRegExp, splitAtColon, stringify, utf8Encode} from '../src/util';
|
|||||||
['\uDEEE', '\xED\xBB\xAE'],
|
['\uDEEE', '\xED\xBB\xAE'],
|
||||||
['\uDFFF', '\xED\xBF\xBF'],
|
['\uDFFF', '\xED\xBF\xBF'],
|
||||||
];
|
];
|
||||||
tests.forEach(
|
tests.forEach(([input, output]) => { expect(utf8Encode(input)).toEqual(output); });
|
||||||
([input, output]: [string, string]) => { expect(utf8Encode(input)).toEqual(output); });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should work on templates', () => {
|
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) !;
|
.find((node: ChildNode) => node.nodeType === Node.COMMENT_NODE) !;
|
||||||
const lContext = loadLContext(templateComment);
|
const lContext = loadLContext(templateComment);
|
||||||
expect(lContext).toBeDefined();
|
expect(lContext).toBeDefined();
|
||||||
@ -252,7 +252,7 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should work on ng-container', () => {
|
it('should work on ng-container', () => {
|
||||||
const ngContainerComment = Array.from(fixture.nativeElement.childNodes)
|
const ngContainerComment = Array.from((fixture.nativeElement as HTMLElement).childNodes)
|
||||||
.find(
|
.find(
|
||||||
(node: ChildNode) => node.nodeType === Node.COMMENT_NODE &&
|
(node: ChildNode) => node.nodeType === Node.COMMENT_NODE &&
|
||||||
node.textContent === `ng-container`) !;
|
node.textContent === `ng-container`) !;
|
||||||
|
@ -42,7 +42,8 @@ describe('property interpolation', () => {
|
|||||||
const fixture = TestBed.createComponent(App);
|
const fixture = TestBed.createComponent(App);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const titles = Array.from(fixture.nativeElement.querySelectorAll('div[title]'))
|
const titles =
|
||||||
|
Array.from(<NodeListOf<HTMLDivElement>>fixture.nativeElement.querySelectorAll('div[title]'))
|
||||||
.map((div: HTMLDivElement) => div.title);
|
.map((div: HTMLDivElement) => div.title);
|
||||||
|
|
||||||
expect(titles).toEqual([
|
expect(titles).toEqual([
|
||||||
@ -194,7 +195,9 @@ describe('property interpolation', () => {
|
|||||||
const fixture = TestBed.createComponent(AppComp);
|
const fixture = TestBed.createComponent(AppComp);
|
||||||
fixture.detectChanges();
|
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);
|
.map((img: HTMLImageElement) => img.title);
|
||||||
|
|
||||||
expect(titles).toEqual([
|
expect(titles).toEqual([
|
||||||
@ -210,7 +213,8 @@ describe('property interpolation', () => {
|
|||||||
'1',
|
'1',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const others = Array.from(fixture.nativeElement.querySelectorAll('img[alt]'))
|
const others =
|
||||||
|
Array.from(<NodeListOf<HTMLImageElement>>fixture.nativeElement.querySelectorAll('img[alt]'))
|
||||||
.map((img: HTMLImageElement) => img.alt);
|
.map((img: HTMLImageElement) => img.alt);
|
||||||
|
|
||||||
expect(others).toEqual([
|
expect(others).toEqual([
|
||||||
|
@ -182,8 +182,8 @@ function getRendererFactory2(document: any): RendererFactory2 {
|
|||||||
const rendererFactory = new ServerRendererFactory2(
|
const rendererFactory = new ServerRendererFactory2(
|
||||||
eventManager, fakeNgZone, document, new ɵDomSharedStylesHost(document));
|
eventManager, fakeNgZone, document, new ɵDomSharedStylesHost(document));
|
||||||
const origCreateRenderer = rendererFactory.createRenderer;
|
const origCreateRenderer = rendererFactory.createRenderer;
|
||||||
rendererFactory.createRenderer = function() {
|
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
|
||||||
const renderer = origCreateRenderer.apply(this, arguments);
|
const renderer = origCreateRenderer.call(this, element, type);
|
||||||
renderer.destroyNode = () => {};
|
renderer.destroyNode = () => {};
|
||||||
return renderer;
|
return renderer;
|
||||||
};
|
};
|
||||||
|
@ -41,7 +41,8 @@ describe('text instructions', () => {
|
|||||||
const fixture = TestBed.createComponent(App);
|
const fixture = TestBed.createComponent(App);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const allTextContent = Array.from(fixture.nativeElement.querySelectorAll('div'))
|
const allTextContent =
|
||||||
|
Array.from((fixture.nativeElement as HTMLElement).querySelectorAll('div'))
|
||||||
.map((div: HTMLDivElement) => div.textContent);
|
.map((div: HTMLDivElement) => div.textContent);
|
||||||
|
|
||||||
expect(allTextContent).toEqual([
|
expect(allTextContent).toEqual([
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {CommonModule, DOCUMENT} from '@angular/common';
|
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 {Input} from '@angular/core/src/metadata';
|
||||||
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
|
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
|
||||||
import {TestBed, TestComponentRenderer} from '@angular/core/testing';
|
import {TestBed, TestComponentRenderer} from '@angular/core/testing';
|
||||||
@ -541,8 +541,8 @@ describe('ViewContainerRef', () => {
|
|||||||
const _origRendererFactory = TestBed.get(RendererFactory2) as RendererFactory2;
|
const _origRendererFactory = TestBed.get(RendererFactory2) as RendererFactory2;
|
||||||
const _origCreateRenderer = _origRendererFactory.createRenderer;
|
const _origCreateRenderer = _origRendererFactory.createRenderer;
|
||||||
|
|
||||||
_origRendererFactory.createRenderer = function() {
|
_origRendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
|
||||||
const renderer = _origCreateRenderer.apply(_origRendererFactory, arguments);
|
const renderer = _origCreateRenderer.call(_origRendererFactory, element, type);
|
||||||
renderer.destroyNode = () => {};
|
renderer.destroyNode = () => {};
|
||||||
return renderer;
|
return renderer;
|
||||||
};
|
};
|
||||||
|
@ -376,9 +376,8 @@ const DEFAULT_COMPONENT_ID = '1';
|
|||||||
it('should allow a transition to use a function to determine what method to run and expose any parameter values',
|
it('should allow a transition to use a function to determine what method to run and expose any parameter values',
|
||||||
() => {
|
() => {
|
||||||
const transitionFn =
|
const transitionFn =
|
||||||
(fromState: string, toState: string, element: any, params: {[key: string]: any}) => {
|
(fromState: string, toState: string, element?: any,
|
||||||
return params['doMatch'] == true;
|
params?: {[key: string]: any}) => { return params !['doMatch'] == true; };
|
||||||
};
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'if-cmp',
|
selector: 'if-cmp',
|
||||||
|
@ -298,7 +298,8 @@ class ComplexItem {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('forEachOperation', () => {
|
describe('forEachOperation', () => {
|
||||||
function stringifyItemChange(record: any, p: number, c: number, originalIndex: number) {
|
function stringifyItemChange(
|
||||||
|
record: any, p: number | null, c: number | null, originalIndex: number) {
|
||||||
const suffix = originalIndex == null ? '' : ' [o=' + originalIndex + ']';
|
const suffix = originalIndex == null ? '' : ' [o=' + originalIndex + ']';
|
||||||
const value = record.item;
|
const value = record.item;
|
||||||
if (record.currentIndex == null) {
|
if (record.currentIndex == null) {
|
||||||
@ -311,11 +312,13 @@ class ComplexItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function modifyArrayUsingOperation(
|
function modifyArrayUsingOperation(
|
||||||
arr: number[], endData: any[], prev: number, next: number) {
|
arr: number[], endData: any[], prev: number | null, next: number | null) {
|
||||||
let value: number = null !;
|
let value: number = null !;
|
||||||
if (prev == null) {
|
if (prev == null) {
|
||||||
value = endData[next];
|
// "next" index is guaranteed to be set since the previous index is
|
||||||
arr.splice(next, 0, value);
|
// not defined and therefore a new entry is added.
|
||||||
|
value = endData[next !];
|
||||||
|
arr.splice(next !, 0, value);
|
||||||
} else if (next == null) {
|
} else if (next == null) {
|
||||||
value = arr[prev];
|
value = arr[prev];
|
||||||
arr.splice(prev, 1);
|
arr.splice(prev, 1);
|
||||||
@ -336,7 +339,7 @@ class ComplexItem {
|
|||||||
differ = differ.diff(endData) !;
|
differ = differ.diff(endData) !;
|
||||||
|
|
||||||
const operations: string[] = [];
|
const operations: string[] = [];
|
||||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
|
||||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||||
});
|
});
|
||||||
@ -359,7 +362,7 @@ class ComplexItem {
|
|||||||
differ = differ.diff(endData) !;
|
differ = differ.diff(endData) !;
|
||||||
|
|
||||||
const operations: string[] = [];
|
const operations: string[] = [];
|
||||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
|
||||||
modifyArrayUsingOperation(startData, endData, prev, next);
|
modifyArrayUsingOperation(startData, endData, prev, next);
|
||||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||||
});
|
});
|
||||||
@ -379,7 +382,7 @@ class ComplexItem {
|
|||||||
differ = differ.diff(endData) !;
|
differ = differ.diff(endData) !;
|
||||||
|
|
||||||
const operations: string[] = [];
|
const operations: string[] = [];
|
||||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
|
||||||
modifyArrayUsingOperation(startData, endData, prev, next);
|
modifyArrayUsingOperation(startData, endData, prev, next);
|
||||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||||
});
|
});
|
||||||
@ -400,7 +403,7 @@ class ComplexItem {
|
|||||||
differ = differ.diff(endData) !;
|
differ = differ.diff(endData) !;
|
||||||
|
|
||||||
const operations: string[] = [];
|
const operations: string[] = [];
|
||||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
|
||||||
modifyArrayUsingOperation(startData, endData, prev, next);
|
modifyArrayUsingOperation(startData, endData, prev, next);
|
||||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||||
});
|
});
|
||||||
@ -421,7 +424,7 @@ class ComplexItem {
|
|||||||
differ = differ.diff(endData) !;
|
differ = differ.diff(endData) !;
|
||||||
|
|
||||||
const operations: string[] = [];
|
const operations: string[] = [];
|
||||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
|
||||||
modifyArrayUsingOperation(startData, endData, prev, next);
|
modifyArrayUsingOperation(startData, endData, prev, next);
|
||||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||||
});
|
});
|
||||||
@ -447,7 +450,7 @@ class ComplexItem {
|
|||||||
differ = differ.diff(endData) !;
|
differ = differ.diff(endData) !;
|
||||||
|
|
||||||
const operations: string[] = [];
|
const operations: string[] = [];
|
||||||
differ.forEachOperation((item: any, prev: number, next: number) => {
|
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
|
||||||
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
const value = modifyArrayUsingOperation(startData, endData, prev, next);
|
||||||
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
|
||||||
});
|
});
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import {ResourceLoader, UrlResolver} from '@angular/compiler';
|
import {ResourceLoader, UrlResolver} from '@angular/compiler';
|
||||||
import {MockResourceLoader} from '@angular/compiler/testing';
|
import {MockResourceLoader} from '@angular/compiler/testing';
|
||||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, DebugElement, Directive, DoCheck, EventEmitter, HostBinding, Inject, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, Provider, RenderComponentType, Renderer, RendererFactory2, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, WrappedValue} from '@angular/core';
|
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, DebugElement, Directive, DoCheck, EventEmitter, HostBinding, Inject, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, Provider, RenderComponentType, Renderer, RendererFactory2, RendererType2, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, WrappedValue} from '@angular/core';
|
||||||
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
|
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
|
||||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
@ -1718,8 +1718,8 @@ function patchLoggingRenderer2(rendererFactory: RendererFactory2, log: RenderLog
|
|||||||
}
|
}
|
||||||
(<any>rendererFactory).__patchedForLogging = true;
|
(<any>rendererFactory).__patchedForLogging = true;
|
||||||
const origCreateRenderer = rendererFactory.createRenderer;
|
const origCreateRenderer = rendererFactory.createRenderer;
|
||||||
rendererFactory.createRenderer = function() {
|
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
|
||||||
const renderer = origCreateRenderer.apply(this, arguments);
|
const renderer = origCreateRenderer.call(this, element, type);
|
||||||
if ((<any>renderer).__patchedForLogging) {
|
if ((<any>renderer).__patchedForLogging) {
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import {ɵAnimationEngine, ɵNoopAnimationStyleNormalizer} from '@angular/animations/browser';
|
import {ɵAnimationEngine, ɵNoopAnimationStyleNormalizer} from '@angular/animations/browser';
|
||||||
import {MockAnimationDriver} from '@angular/animations/browser/testing';
|
import {MockAnimationDriver} from '@angular/animations/browser/testing';
|
||||||
import {NgZone, RendererFactory2} from '@angular/core';
|
import {NgZone, RendererFactory2, RendererType2} from '@angular/core';
|
||||||
import {NoopNgZone} from '@angular/core/src/zone/ng_zone';
|
import {NoopNgZone} from '@angular/core/src/zone/ng_zone';
|
||||||
import {EventManager, ɵDomRendererFactory2, ɵDomSharedStylesHost} from '@angular/platform-browser';
|
import {EventManager, ɵDomRendererFactory2, ɵDomSharedStylesHost} from '@angular/platform-browser';
|
||||||
import {ɵAnimationRendererFactory} from '@angular/platform-browser/animations';
|
import {ɵAnimationRendererFactory} from '@angular/platform-browser/animations';
|
||||||
@ -37,8 +37,8 @@ export function getRendererFactory2(document: any): RendererFactory2 {
|
|||||||
const rendererFactory =
|
const rendererFactory =
|
||||||
new ɵDomRendererFactory2(eventManager, new ɵDomSharedStylesHost(document), 'dummyappid');
|
new ɵDomRendererFactory2(eventManager, new ɵDomSharedStylesHost(document), 'dummyappid');
|
||||||
const origCreateRenderer = rendererFactory.createRenderer;
|
const origCreateRenderer = rendererFactory.createRenderer;
|
||||||
rendererFactory.createRenderer = function() {
|
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
|
||||||
const renderer = origCreateRenderer.apply(this, arguments);
|
const renderer = origCreateRenderer.call(this, element, type);
|
||||||
renderer.destroyNode = () => {};
|
renderer.destroyNode = () => {};
|
||||||
return renderer;
|
return renderer;
|
||||||
};
|
};
|
||||||
@ -86,8 +86,8 @@ export function patchLoggingRenderer2(rendererFactory: RendererFactory2, log: Re
|
|||||||
}
|
}
|
||||||
(<any>rendererFactory).__patchedForLogging = true;
|
(<any>rendererFactory).__patchedForLogging = true;
|
||||||
const origCreateRenderer = rendererFactory.createRenderer;
|
const origCreateRenderer = rendererFactory.createRenderer;
|
||||||
rendererFactory.createRenderer = function() {
|
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
|
||||||
const renderer = origCreateRenderer.apply(this, arguments);
|
const renderer = origCreateRenderer.call(this, element, type);
|
||||||
if ((<any>renderer).__patchedForLogging) {
|
if ((<any>renderer).__patchedForLogging) {
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
@ -2604,7 +2604,7 @@ describe('style and class based bindings', () => {
|
|||||||
const players: MockPlayer[] = [];
|
const players: MockPlayer[] = [];
|
||||||
const buildFn =
|
const buildFn =
|
||||||
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
|
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
|
||||||
oldPlayer: MockPlayer | null) => {
|
oldPlayer: Player | null) => {
|
||||||
const player = new MockPlayer(value);
|
const player = new MockPlayer(value);
|
||||||
players.push(player);
|
players.push(player);
|
||||||
return player;
|
return player;
|
||||||
@ -2932,8 +2932,8 @@ describe('style and class based bindings', () => {
|
|||||||
let currentPlayer: MockPlayer|null = null;
|
let currentPlayer: MockPlayer|null = null;
|
||||||
const buildFn =
|
const buildFn =
|
||||||
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
|
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
|
||||||
existingPlayer: MockPlayer) => {
|
existingPlayer: Player | null) => {
|
||||||
previousPlayer = existingPlayer;
|
previousPlayer = existingPlayer as MockPlayer | null;
|
||||||
return currentPlayer = new MockPlayer(value);
|
return currentPlayer = new MockPlayer(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2962,8 +2962,8 @@ describe('style and class based bindings', () => {
|
|||||||
let previousPlayer: MockPlayer|null = null;
|
let previousPlayer: MockPlayer|null = null;
|
||||||
const buildFn =
|
const buildFn =
|
||||||
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
|
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
|
||||||
existingPlayer: MockPlayer | null) => {
|
existingPlayer: Player | null) => {
|
||||||
previousPlayer = existingPlayer;
|
previousPlayer = existingPlayer as MockPlayer | null;
|
||||||
return currentPlayer = new MockPlayer(value);
|
return currentPlayer = new MockPlayer(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ if (browserDetection.supportsCustomElements) {
|
|||||||
element.connectedCallback();
|
element.connectedCallback();
|
||||||
|
|
||||||
let eventValue: any = null;
|
let eventValue: any = null;
|
||||||
element.addEventListener('some-event', (e: CustomEvent) => eventValue = e.detail);
|
element.addEventListener('some-event', (e: Event) => eventValue = (e as CustomEvent).detail);
|
||||||
strategy.events.next({name: 'some-event', value: 'event-value'});
|
strategy.events.next({name: 'some-event', value: 'event-value'});
|
||||||
|
|
||||||
expect(eventValue).toEqual('event-value');
|
expect(eventValue).toEqual('event-value');
|
||||||
@ -80,7 +80,7 @@ if (browserDetection.supportsCustomElements) {
|
|||||||
expect(strategy.disconnectCalled).toBe(true);
|
expect(strategy.disconnectCalled).toBe(true);
|
||||||
|
|
||||||
let eventValue: any = null;
|
let eventValue: any = null;
|
||||||
element.addEventListener('some-event', (e: CustomEvent) => eventValue = e.detail);
|
element.addEventListener('some-event', (e: Event) => eventValue = (e as CustomEvent).detail);
|
||||||
strategy.events.next({name: 'some-event', value: 'event-value'});
|
strategy.events.next({name: 'some-event', value: 'event-value'});
|
||||||
|
|
||||||
expect(eventValue).toEqual(null);
|
expect(eventValue).toEqual(null);
|
||||||
|
@ -10,7 +10,7 @@ import {extractProjectableNodes} from '../src/extract-projectable-nodes';
|
|||||||
|
|
||||||
describe('extractProjectableNodes()', () => {
|
describe('extractProjectableNodes()', () => {
|
||||||
let elem: HTMLElement;
|
let elem: HTMLElement;
|
||||||
let childNodes: NodeList;
|
let childNodes: ChildNode[];
|
||||||
|
|
||||||
const expectProjectableNodes = (matches: {[selector: string]: number[]}) => {
|
const expectProjectableNodes = (matches: {[selector: string]: number[]}) => {
|
||||||
const selectors = Object.keys(matches);
|
const selectors = Object.keys(matches);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import {fakeAsync, tick} from '@angular/core/testing';
|
import {fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms';
|
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, ValidatorFn} from '@angular/forms';
|
||||||
import {Validators} from '@angular/forms/src/validators';
|
import {Validators} from '@angular/forms/src/validators';
|
||||||
import {of } from 'rxjs';
|
import {of } from 'rxjs';
|
||||||
|
|
||||||
@ -626,7 +626,7 @@ import {of } from 'rxjs';
|
|||||||
c.controls[0].value != 'correct' ? {'broken': true} : null;
|
c.controls[0].value != 'correct' ? {'broken': true} : null;
|
||||||
|
|
||||||
const c = new FormControl(null);
|
const c = new FormControl(null);
|
||||||
const g = new FormArray([c], simpleValidator);
|
const g = new FormArray([c], simpleValidator as ValidatorFn);
|
||||||
|
|
||||||
c.setValue('correct');
|
c.setValue('correct');
|
||||||
|
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
import {EventEmitter} from '@angular/core';
|
import {EventEmitter} from '@angular/core';
|
||||||
import {fakeAsync, tick} from '@angular/core/testing';
|
import {fakeAsync, tick} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||||
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
import {AbstractControl, AsyncValidatorFn, FormControl, FormGroup, Validators} from '@angular/forms';
|
||||||
|
|
||||||
import {FormArray} from '@angular/forms/src/model';
|
import {FormArray} from '@angular/forms/src/model';
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
function asyncValidator(expected: string, timeouts = {}) {
|
function asyncValidator(expected: string, timeouts = {}): AsyncValidatorFn {
|
||||||
return (c: FormControl) => {
|
return (c: AbstractControl) => {
|
||||||
let resolve: (result: any) => void = undefined !;
|
let resolve: (result: any) => void = undefined !;
|
||||||
const promise = new Promise(res => { resolve = res; });
|
const promise = new Promise(res => { resolve = res; });
|
||||||
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
|
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
|
||||||
@ -31,7 +31,7 @@ import {FormArray} from '@angular/forms/src/model';
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function asyncValidatorReturningObservable(c: FormControl) {
|
function asyncValidatorReturningObservable(c: AbstractControl) {
|
||||||
const e = new EventEmitter();
|
const e = new EventEmitter();
|
||||||
Promise.resolve(null).then(() => { e.emit({'async': true}); });
|
Promise.resolve(null).then(() => { e.emit({'async': true}); });
|
||||||
return e;
|
return e;
|
||||||
|
@ -35,7 +35,7 @@ import {of } from 'rxjs';
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function asyncValidatorReturningObservable(c: FormControl) {
|
function asyncValidatorReturningObservable(c: AbstractControl) {
|
||||||
const e = new EventEmitter();
|
const e = new EventEmitter();
|
||||||
Promise.resolve(null).then(() => { e.emit({'async': true}); });
|
Promise.resolve(null).then(() => { e.emit({'async': true}); });
|
||||||
return e;
|
return e;
|
||||||
|
@ -329,35 +329,35 @@ import {first, map} from 'rxjs/operators';
|
|||||||
const v = Validators.composeAsync(
|
const v = Validators.composeAsync(
|
||||||
[promiseValidator({'one': true}), promiseValidator({'two': true})]) !;
|
[promiseValidator({'one': true}), promiseValidator({'two': true})]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(errorMap).toEqual({'one': true, 'two': true});
|
expect(errorMap !).toEqual({'one': true, 'two': true});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should normalize and evaluate async validator-directives correctly', fakeAsync(() => {
|
it('should normalize and evaluate async validator-directives correctly', fakeAsync(() => {
|
||||||
const v = Validators.composeAsync([normalizeAsyncValidator(
|
const v = Validators.composeAsync([normalizeAsyncValidator(
|
||||||
new AsyncValidatorDirective('expected', {'one': true}))]) !;
|
new AsyncValidatorDirective('expected', {'one': true}))]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(errorMap).toEqual({'one': true});
|
expect(errorMap !).toEqual({'one': true});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return null when no errors', fakeAsync(() => {
|
it('should return null when no errors', fakeAsync(() => {
|
||||||
const v = Validators.composeAsync([promiseValidator({'one': true})]) !;
|
const v = Validators.composeAsync([promiseValidator({'one': true})]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(errorMap).toBeNull();
|
expect(errorMap).toBeNull();
|
||||||
@ -366,13 +366,13 @@ import {first, map} from 'rxjs/operators';
|
|||||||
it('should ignore nulls', fakeAsync(() => {
|
it('should ignore nulls', fakeAsync(() => {
|
||||||
const v = Validators.composeAsync([promiseValidator({'one': true}), null !]) !;
|
const v = Validators.composeAsync([promiseValidator({'one': true}), null !]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(errorMap).toEqual({'one': true});
|
expect(errorMap !).toEqual({'one': true});
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -391,33 +391,33 @@ import {first, map} from 'rxjs/operators';
|
|||||||
const v = Validators.composeAsync(
|
const v = Validators.composeAsync(
|
||||||
[observableValidator({'one': true}), observableValidator({'two': true})]) !;
|
[observableValidator({'one': true}), observableValidator({'two': true})]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
|
|
||||||
expect(errorMap).toEqual({'one': true, 'two': true});
|
expect(errorMap !).toEqual({'one': true, 'two': true});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should normalize and evaluate async validator-directives correctly', () => {
|
it('should normalize and evaluate async validator-directives correctly', () => {
|
||||||
const v = Validators.composeAsync(
|
const v = Validators.composeAsync(
|
||||||
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]) !;
|
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors) !;
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors) !;
|
||||||
|
|
||||||
expect(errorMap).toEqual({'one': true});
|
expect(errorMap !).toEqual({'one': true});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when no errors', () => {
|
it('should return null when no errors', () => {
|
||||||
const v = Validators.composeAsync([observableValidator({'one': true})]) !;
|
const v = Validators.composeAsync([observableValidator({'one': true})]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
|
|
||||||
expect(errorMap).toBeNull();
|
expect(errorMap).toBeNull();
|
||||||
});
|
});
|
||||||
@ -425,12 +425,12 @@ import {first, map} from 'rxjs/operators';
|
|||||||
it('should ignore nulls', () => {
|
it('should ignore nulls', () => {
|
||||||
const v = Validators.composeAsync([observableValidator({'one': true}), null !]) !;
|
const v = Validators.composeAsync([observableValidator({'one': true}), null !]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
|
|
||||||
expect(errorMap).toEqual({'one': true});
|
expect(errorMap !).toEqual({'one': true});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should wait for all validators before setting errors', fakeAsync(() => {
|
it('should wait for all validators before setting errors', fakeAsync(() => {
|
||||||
@ -441,18 +441,20 @@ import {first, map} from 'rxjs/operators';
|
|||||||
const v = Validators.composeAsync(
|
const v = Validators.composeAsync(
|
||||||
[getTimerObs(100, {one: true}), getTimerObs(200, {two: true})]) !;
|
[getTimerObs(100, {one: true}), getTimerObs(200, {two: true})]) !;
|
||||||
|
|
||||||
let errorMap: {[key: string]: any} = undefined !;
|
let errorMap: {[key: string]: any}|null = undefined !;
|
||||||
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
|
||||||
.pipe(first())
|
.pipe(first())
|
||||||
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
|
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
|
||||||
|
|
||||||
tick(100);
|
tick(100);
|
||||||
expect(errorMap).not.toBeDefined(
|
expect(errorMap).not.toBeDefined(
|
||||||
`Expected errors not to be set until all validators came back.`);
|
`Expected errors not to be set until all validators came back.`);
|
||||||
|
|
||||||
tick(100);
|
tick(100);
|
||||||
expect(errorMap).toEqual(
|
expect(errorMap !)
|
||||||
{one: true, two: true}, `Expected errors to merge once all validators resolved.`);
|
.toEqual(
|
||||||
|
{one: true, two: true},
|
||||||
|
`Expected errors to merge once all validators resolved.`);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -274,8 +274,9 @@ function buildUp(originalText: string, cb: (text: string, position: number) => v
|
|||||||
inString[index] = true;
|
inString[index] = true;
|
||||||
unused.splice(unusedIndex, 1);
|
unused.splice(unusedIndex, 1);
|
||||||
let text = getText();
|
let text = getText();
|
||||||
let position =
|
let position = inString.filter((_, i) => i <= index)
|
||||||
inString.filter((_, i) => i <= index).map(v => v ? 1 : 0).reduce((p, v) => p + v, 0);
|
.map(v => v ? 1 : 0)
|
||||||
|
.reduce((p: number, v) => p + v, 0);
|
||||||
cb(text, position);
|
cb(text, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,13 +115,15 @@ class CompWithUrlTemplate {
|
|||||||
{
|
{
|
||||||
describe('public testing API', () => {
|
describe('public testing API', () => {
|
||||||
describe('using the async helper with context passing', () => {
|
describe('using the async helper with context passing', () => {
|
||||||
beforeEach(function() { this.actuallyDone = false; });
|
type TestContext = {actuallyDone: boolean};
|
||||||
|
|
||||||
afterEach(function() { expect(this.actuallyDone).toEqual(true); });
|
beforeEach(function(this: TestContext) { this.actuallyDone = false; });
|
||||||
|
|
||||||
it('should run normal tests', function() { this.actuallyDone = true; });
|
afterEach(function(this: TestContext) { expect(this.actuallyDone).toEqual(true); });
|
||||||
|
|
||||||
it('should run normal async tests', function(done) {
|
it('should run normal tests', function(this: TestContext) { this.actuallyDone = true; });
|
||||||
|
|
||||||
|
it('should run normal async tests', function(this: TestContext, done) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.actuallyDone = true;
|
this.actuallyDone = true;
|
||||||
done();
|
done();
|
||||||
@ -129,9 +131,9 @@ class CompWithUrlTemplate {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should run async tests with tasks',
|
it('should run async tests with tasks',
|
||||||
async(function() { setTimeout(() => this.actuallyDone = true, 0); }));
|
async(function(this: TestContext) { setTimeout(() => this.actuallyDone = true, 0); }));
|
||||||
|
|
||||||
it('should run async tests with promises', async(function() {
|
it('should run async tests with promises', async(function(this: TestContext) {
|
||||||
const p = new Promise((resolve, reject) => setTimeout(resolve, 10));
|
const p = new Promise((resolve, reject) => setTimeout(resolve, 10));
|
||||||
p.then(() => this.actuallyDone = true);
|
p.then(() => this.actuallyDone = true);
|
||||||
}));
|
}));
|
||||||
@ -142,30 +144,35 @@ class CompWithUrlTemplate {
|
|||||||
providers: [FancyService],
|
providers: [FancyService],
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() { this.contextModified = false; });
|
type TestContext = {contextModified: boolean};
|
||||||
|
|
||||||
afterEach(function() { expect(this.contextModified).toEqual(true); });
|
beforeEach(function(this: TestContext) { this.contextModified = false; });
|
||||||
|
|
||||||
|
afterEach(function(this: TestContext) { expect(this.contextModified).toEqual(true); });
|
||||||
|
|
||||||
it('should pass context to inject helper',
|
it('should pass context to inject helper',
|
||||||
inject([], function() { this.contextModified = true; }));
|
inject([], function(this: TestContext) { this.contextModified = true; }));
|
||||||
|
|
||||||
it('should pass context to fakeAsync helper',
|
it('should pass context to fakeAsync helper',
|
||||||
fakeAsync(function() { this.contextModified = true; }));
|
fakeAsync(function(this: TestContext) { this.contextModified = true; }));
|
||||||
|
|
||||||
it('should pass context to withModule helper - simple',
|
it('should pass context to withModule helper - simple',
|
||||||
withModule(moduleConfig, function() { this.contextModified = true; }));
|
withModule(moduleConfig, function(this: TestContext) { this.contextModified = true; }));
|
||||||
|
|
||||||
it('should pass context to withModule helper - advanced',
|
it('should pass context to withModule helper - advanced',
|
||||||
withModule(moduleConfig).inject([FancyService], function(service: FancyService) {
|
withModule(moduleConfig)
|
||||||
|
.inject([FancyService], function(this: TestContext, service: FancyService) {
|
||||||
expect(service.value).toBe('real value');
|
expect(service.value).toBe('real value');
|
||||||
this.contextModified = true;
|
this.contextModified = true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should preserve context when async and inject helpers are combined',
|
it('should preserve context when async and inject helpers are combined',
|
||||||
async(inject([], function() { setTimeout(() => this.contextModified = true, 0); })));
|
async(inject([], function(this: TestContext) {
|
||||||
|
setTimeout(() => this.contextModified = true, 0);
|
||||||
|
})));
|
||||||
|
|
||||||
it('should preserve context when fakeAsync and inject helpers are combined',
|
it('should preserve context when fakeAsync and inject helpers are combined',
|
||||||
fakeAsync(inject([], function() {
|
fakeAsync(inject([], function(this: TestContext) {
|
||||||
setTimeout(() => this.contextModified = true, 0);
|
setTimeout(() => this.contextModified = true, 0);
|
||||||
tick(1);
|
tick(1);
|
||||||
})));
|
})));
|
||||||
|
@ -776,7 +776,7 @@ class HiddenModule {
|
|||||||
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
|
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
|
||||||
const http = ref.injector.get(HttpClient);
|
const http = ref.injector.get(HttpClient);
|
||||||
ref.injector.get<NgZone>(NgZone).run(() => {
|
ref.injector.get<NgZone>(NgZone).run(() => {
|
||||||
http.get('http://localhost/testing').subscribe(body => {
|
http.get('http://localhost/testing').subscribe((body: string) => {
|
||||||
NgZone.assertInAngularZone();
|
NgZone.assertInAngularZone();
|
||||||
expect(body).toEqual('success!');
|
expect(body).toEqual('success!');
|
||||||
});
|
});
|
||||||
@ -792,7 +792,7 @@ class HiddenModule {
|
|||||||
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
|
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
|
||||||
const http = ref.injector.get(HttpClient);
|
const http = ref.injector.get(HttpClient);
|
||||||
ref.injector.get<NgZone>(NgZone).run(() => {
|
ref.injector.get<NgZone>(NgZone).run(() => {
|
||||||
http.get('http://localhost/testing').subscribe(body => {
|
http.get('http://localhost/testing').subscribe((body: string) => {
|
||||||
expect(body).toEqual('success!');
|
expect(body).toEqual('success!');
|
||||||
});
|
});
|
||||||
expect(ref.injector.get<NgZone>(NgZone).hasPendingMacrotasks).toBeTruthy();
|
expect(ref.injector.get<NgZone>(NgZone).hasPendingMacrotasks).toBeTruthy();
|
||||||
@ -809,7 +809,7 @@ class HiddenModule {
|
|||||||
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
|
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
|
||||||
const http = ref.injector.get(HttpClient);
|
const http = ref.injector.get(HttpClient);
|
||||||
ref.injector.get<NgZone>(NgZone).run(() => {
|
ref.injector.get<NgZone>(NgZone).run(() => {
|
||||||
http.get('http://localhost/testing').subscribe(body => {
|
http.get('http://localhost/testing').subscribe((body: string) => {
|
||||||
NgZone.assertInAngularZone();
|
NgZone.assertInAngularZone();
|
||||||
expect(body).toEqual('success!');
|
expect(body).toEqual('success!');
|
||||||
});
|
});
|
||||||
|
@ -118,7 +118,7 @@ describe('bootstrap', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
platformBrowserDynamic([]).bootstrapModule(TestModule).then(res => {
|
platformBrowserDynamic([]).bootstrapModule(TestModule).then(res => {
|
||||||
const router = res.injector.get(Router);
|
const router: Router = res.injector.get(Router);
|
||||||
expect(router.routerState.snapshot.root.firstChild).toBeNull();
|
expect(router.routerState.snapshot.root.firstChild).toBeNull();
|
||||||
// ResolveEnd has not been emitted yet because bootstrap returned too early
|
// ResolveEnd has not been emitted yet because bootstrap returned too early
|
||||||
expect(log).toEqual([
|
expect(log).toEqual([
|
||||||
|
@ -3628,7 +3628,8 @@ describe('Integration', () => {
|
|||||||
const recordedEvents: any[] = [];
|
const recordedEvents: any[] = [];
|
||||||
|
|
||||||
const navStart$ = router.events.pipe(
|
const navStart$ = router.events.pipe(
|
||||||
tap(e => recordedEvents.push(e)), filter(e => e instanceof NavigationStart), first());
|
tap(e => recordedEvents.push(e)),
|
||||||
|
filter((e): e is NavigationStart => e instanceof NavigationStart), first());
|
||||||
|
|
||||||
navStart$.subscribe((e: NavigationStart | NavigationError) => {
|
navStart$.subscribe((e: NavigationStart | NavigationError) => {
|
||||||
router.navigate(
|
router.navigate(
|
||||||
|
@ -158,10 +158,15 @@ describe('Router', () => {
|
|||||||
createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}});
|
createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}});
|
||||||
const futureState = new (RouterStateSnapshot as any)(
|
const futureState = new (RouterStateSnapshot as any)(
|
||||||
'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])]));
|
'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])]));
|
||||||
|
// Since we only test the guards, we don't need to provide a full navigation
|
||||||
|
// transition object with all properties set.
|
||||||
|
const testTransition = {
|
||||||
|
guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())
|
||||||
|
} as NavigationTransition;
|
||||||
|
|
||||||
of ({guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())})
|
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
|
||||||
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
|
events.push(evt);
|
||||||
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
expect(events.length).toEqual(2);
|
expect(events.length).toEqual(2);
|
||||||
@ -192,10 +197,15 @@ describe('Router', () => {
|
|||||||
empty.root, [new TreeNode(childSnapshot, [
|
empty.root, [new TreeNode(childSnapshot, [
|
||||||
new TreeNode(grandchildSnapshot, [new TreeNode(greatGrandchildSnapshot, [])])
|
new TreeNode(grandchildSnapshot, [new TreeNode(greatGrandchildSnapshot, [])])
|
||||||
])]));
|
])]));
|
||||||
|
// Since we only test the guards, we don't need to provide a full navigation
|
||||||
|
// transition object with all properties set.
|
||||||
|
const testTransition = {
|
||||||
|
guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())
|
||||||
|
} as NavigationTransition;
|
||||||
|
|
||||||
of ({guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())})
|
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
|
||||||
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
|
events.push(evt);
|
||||||
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
expect(events.length).toEqual(6);
|
expect(events.length).toEqual(6);
|
||||||
@ -224,10 +234,15 @@ describe('Router', () => {
|
|||||||
'url',
|
'url',
|
||||||
new TreeNode(
|
new TreeNode(
|
||||||
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
|
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
|
||||||
|
// Since we only test the guards, we don't need to provide a full navigation
|
||||||
|
// transition object with all properties set.
|
||||||
|
const testTransition = {
|
||||||
|
guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())
|
||||||
|
} as NavigationTransition;
|
||||||
|
|
||||||
of ({guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())})
|
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
|
||||||
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
|
events.push(evt);
|
||||||
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
expect(events.length).toEqual(2);
|
expect(events.length).toEqual(2);
|
||||||
@ -269,10 +284,15 @@ describe('Router', () => {
|
|||||||
new TreeNode(
|
new TreeNode(
|
||||||
greatGrandchildSnapshot, [new TreeNode(greatGreatGrandchildSnapshot, [])])
|
greatGrandchildSnapshot, [new TreeNode(greatGreatGrandchildSnapshot, [])])
|
||||||
])])]));
|
])])]));
|
||||||
|
// Since we only test the guards, we don't need to provide a full navigation
|
||||||
|
// transition object with all properties set.
|
||||||
|
const testTransition = {
|
||||||
|
guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())
|
||||||
|
} as NavigationTransition;
|
||||||
|
|
||||||
of ({guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())})
|
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
|
||||||
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
|
events.push(evt);
|
||||||
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
|
||||||
|
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
expect(events.length).toEqual(4);
|
expect(events.length).toEqual(4);
|
||||||
@ -658,9 +678,11 @@ describe('Router', () => {
|
|||||||
|
|
||||||
function checkResolveData(
|
function checkResolveData(
|
||||||
future: RouterStateSnapshot, curr: RouterStateSnapshot, injector: any, check: any): void {
|
future: RouterStateSnapshot, curr: RouterStateSnapshot, injector: any, check: any): void {
|
||||||
|
// Since we only test the guards and their resolve data function, we don't need to provide
|
||||||
|
// a full navigation transition object with all properties set.
|
||||||
of ({
|
of ({
|
||||||
guards: getAllRouteGuards(future, curr, new ChildrenOutletContexts())
|
guards: getAllRouteGuards(future, curr, new ChildrenOutletContexts())
|
||||||
} as Partial<NavigationTransition>)
|
} as NavigationTransition)
|
||||||
.pipe(resolveDataOperator('emptyOnly', injector))
|
.pipe(resolveDataOperator('emptyOnly', injector))
|
||||||
.subscribe(check, (e) => { throw e; });
|
.subscribe(check, (e) => { throw e; });
|
||||||
}
|
}
|
||||||
@ -668,9 +690,11 @@ function checkResolveData(
|
|||||||
function checkGuards(
|
function checkGuards(
|
||||||
future: RouterStateSnapshot, curr: RouterStateSnapshot, injector: any,
|
future: RouterStateSnapshot, curr: RouterStateSnapshot, injector: any,
|
||||||
check: (result: boolean | UrlTree) => void): void {
|
check: (result: boolean | UrlTree) => void): void {
|
||||||
|
// Since we only test the guards, we don't need to provide a full navigation
|
||||||
|
// transition object with all properties set.
|
||||||
of ({
|
of ({
|
||||||
guards: getAllRouteGuards(future, curr, new ChildrenOutletContexts())
|
guards: getAllRouteGuards(future, curr, new ChildrenOutletContexts())
|
||||||
} as Partial<NavigationTransition>)
|
} as NavigationTransition)
|
||||||
.pipe(checkGuardsOperator(injector))
|
.pipe(checkGuardsOperator(injector))
|
||||||
.subscribe({
|
.subscribe({
|
||||||
next(t) {
|
next(t) {
|
||||||
|
@ -288,7 +288,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||||||
mock.sendMessage({type, data: {message}});
|
mock.sendMessage({type, data: {message}});
|
||||||
|
|
||||||
const receivedMessages: string[] = [];
|
const receivedMessages: string[] = [];
|
||||||
push.messages.subscribe((msg: {message: string}) => receivedMessages.push(msg.message));
|
push.messages.subscribe((msg: any) => receivedMessages.push(msg.message));
|
||||||
|
|
||||||
sendMessage('PUSH', 'this was a push message');
|
sendMessage('PUSH', 'this was a push message');
|
||||||
sendMessage('NOTPUSH', 'this was not a push message');
|
sendMessage('NOTPUSH', 'this was not a push message');
|
||||||
|
@ -27,7 +27,7 @@ export class MockServiceWorkerContainer {
|
|||||||
private onMessage: Function[] = [];
|
private onMessage: Function[] = [];
|
||||||
mockRegistration: MockServiceWorkerRegistration|null = null;
|
mockRegistration: MockServiceWorkerRegistration|null = null;
|
||||||
controller: MockServiceWorker|null = null;
|
controller: MockServiceWorker|null = null;
|
||||||
messages = new Subject();
|
messages = new Subject<any>();
|
||||||
notificationClicks = new Subject();
|
notificationClicks = new Subject();
|
||||||
|
|
||||||
addEventListener(event: 'controllerchange'|'message', handler: Function) {
|
addEventListener(event: 'controllerchange'|'message', handler: Function) {
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
{
|
{
|
||||||
"extends": "./tsconfig-build.json",
|
"extends": "./tsconfig-build.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"strict": false,
|
|
||||||
"types": ["node", "jasmine"],
|
"types": ["node", "jasmine"],
|
||||||
"plugins": [{
|
"plugins": [{
|
||||||
"name": "@bazel/tsetse",
|
"name": "@bazel/tsetse",
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
|
"strict": true,
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"strictPropertyInitialization": true,
|
"strictPropertyInitialization": true,
|
||||||
|
@ -1634,12 +1634,13 @@ withEachNg1Version(() => {
|
|||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: class {$onInit() { $onInitSpyA(); }}
|
controller: class {$onInit() { $onInitSpyA(); }}
|
||||||
}))
|
}))
|
||||||
.directive('ng1B', () => ({
|
.directive(
|
||||||
|
'ng1B', () => ({
|
||||||
template: '',
|
template: '',
|
||||||
scope: {},
|
scope: {},
|
||||||
bindToController: false,
|
bindToController: false,
|
||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: function() { this.$onInit = $onInitSpyB; }
|
controller: function(this: any) { this.$onInit = $onInitSpyB; }
|
||||||
}))
|
}))
|
||||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||||
|
|
||||||
@ -1727,12 +1728,13 @@ withEachNg1Version(() => {
|
|||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: class {$doCheck() { $doCheckSpyA(); }}
|
controller: class {$doCheck() { $doCheckSpyA(); }}
|
||||||
}))
|
}))
|
||||||
.directive('ng1B', () => ({
|
.directive(
|
||||||
|
'ng1B', () => ({
|
||||||
template: '',
|
template: '',
|
||||||
scope: {},
|
scope: {},
|
||||||
bindToController: false,
|
bindToController: false,
|
||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: function() { this.$doCheck = $doCheckSpyB; }
|
controller: function(this: any) { this.$doCheck = $doCheckSpyB; }
|
||||||
}))
|
}))
|
||||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||||
|
|
||||||
@ -1834,12 +1836,13 @@ withEachNg1Version(() => {
|
|||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: class {$postLink() { $postLinkSpyA(); }}
|
controller: class {$postLink() { $postLinkSpyA(); }}
|
||||||
}))
|
}))
|
||||||
.directive('ng1B', () => ({
|
.directive(
|
||||||
|
'ng1B', () => ({
|
||||||
template: '',
|
template: '',
|
||||||
scope: {},
|
scope: {},
|
||||||
bindToController: false,
|
bindToController: false,
|
||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: function() { this.$postLink = $postLinkSpyB; }
|
controller: function(this: any) { this.$postLink = $postLinkSpyB; }
|
||||||
}))
|
}))
|
||||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||||
|
|
||||||
@ -1929,7 +1932,7 @@ withEachNg1Version(() => {
|
|||||||
scope: {valA: '<'},
|
scope: {valA: '<'},
|
||||||
bindToController: true,
|
bindToController: true,
|
||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: function($scope: angular.IScope) {
|
controller: function(this: any, $scope: angular.IScope) {
|
||||||
this.$onChanges = $onChangesControllerSpyA;
|
this.$onChanges = $onChangesControllerSpyA;
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@ -2034,12 +2037,13 @@ withEachNg1Version(() => {
|
|||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: class {$onDestroy() { $onDestroySpyA(); }}
|
controller: class {$onDestroy() { $onDestroySpyA(); }}
|
||||||
}))
|
}))
|
||||||
.directive('ng1B', () => ({
|
.directive(
|
||||||
|
'ng1B', () => ({
|
||||||
template: '',
|
template: '',
|
||||||
scope: {},
|
scope: {},
|
||||||
bindToController: false,
|
bindToController: false,
|
||||||
controllerAs: '$ctrl',
|
controllerAs: '$ctrl',
|
||||||
controller: function() { this.$onDestroy = $onDestroySpyB; }
|
controller: function(this: any) { this.$onDestroy = $onDestroySpyB; }
|
||||||
}))
|
}))
|
||||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||||
|
|
||||||
|
@ -1166,8 +1166,8 @@ withEachNg1Version(() => {
|
|||||||
constructor(injector: Injector) {
|
constructor(injector: Injector) {
|
||||||
const originalGet = injector.get;
|
const originalGet = injector.get;
|
||||||
injector.get = function(token: any) {
|
injector.get = function(token: any) {
|
||||||
if (token === NgZone) ++getNgZoneCount;
|
if (arguments[0] === NgZone) ++getNgZoneCount;
|
||||||
return originalGet.apply(injector, arguments);
|
return originalGet.apply(injector, arguments as any);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
ngDoBootstrap() {}
|
ngDoBootstrap() {}
|
||||||
@ -1192,7 +1192,7 @@ withEachNg1Version(() => {
|
|||||||
|
|
||||||
const injector = ($injector.get(LAZY_MODULE_REF) as LazyModuleRef).injector !;
|
const injector = ($injector.get(LAZY_MODULE_REF) as LazyModuleRef).injector !;
|
||||||
const injectorGet = injector.get;
|
const injectorGet = injector.get;
|
||||||
spyOn(injector, 'get').and.callFake((...args: any[]) => {
|
spyOn(injector, 'get').and.callFake((...args: [any, any?]) => {
|
||||||
expect(args[0]).not.toBe(NgZone);
|
expect(args[0]).not.toBe(NgZone);
|
||||||
return injectorGet.apply(injector, args);
|
return injectorGet.apply(injector, args);
|
||||||
});
|
});
|
||||||
|
@ -777,7 +777,7 @@ withEachNg1Version(() => {
|
|||||||
C: {{ $ctrl.modelC }}
|
C: {{ $ctrl.modelC }}
|
||||||
`,
|
`,
|
||||||
bindings: {fullName: '@', modelA: '<dataA', modelB: '=dataB', modelC: '=', event: '&'},
|
bindings: {fullName: '@', modelA: '<dataA', modelB: '=dataB', modelC: '=', event: '&'},
|
||||||
controller: function($scope: angular.IScope) {
|
controller: function(this: any, $scope: angular.IScope) {
|
||||||
$scope.$watch('$ctrl.modelB', (v: string) => {
|
$scope.$watch('$ctrl.modelB', (v: string) => {
|
||||||
if (v === 'Savkin') {
|
if (v === 'Savkin') {
|
||||||
this.modelB = 'SAVKIN';
|
this.modelB = 'SAVKIN';
|
||||||
@ -971,7 +971,7 @@ withEachNg1Version(() => {
|
|||||||
const ng1Directive: angular.IDirective = {
|
const ng1Directive: angular.IDirective = {
|
||||||
template: '{{ someText }} - Data: {{ inputA }} - Length: {{ inputA.length }}',
|
template: '{{ someText }} - Data: {{ inputA }} - Length: {{ inputA.length }}',
|
||||||
scope: {inputA: '=', outputA: '&'},
|
scope: {inputA: '=', outputA: '&'},
|
||||||
controller: function($scope: angular.IScope) {
|
controller: function(this: any, $scope: angular.IScope) {
|
||||||
$scope['someText'] = 'ng1';
|
$scope['someText'] = 'ng1';
|
||||||
this.$scope = $scope;
|
this.$scope = $scope;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user