From 23bc8edf24a702f944bbf3cd6099c3ec865a8642 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Thu, 29 Nov 2018 23:34:28 +0100 Subject: [PATCH] test: move remaining fixmeIvy to test level (#27354) Moves all of the remaning `describe`-level fixme instances to the `it` level. PR Close #27354 --- packages/core/test/component_fixture_spec.ts | 388 +++--- packages/core/test/debug/debug_node_spec.ts | 30 +- .../directive_lifecycle_integration_spec.ts | 29 +- packages/core/test/fake_async_spec.ts | 406 +++---- .../core/test/forward_ref_integration_spec.ts | 16 +- .../linker/jit_summaries_integration_spec.ts | 232 ++-- .../test/linker/query_integration_spec.ts | 1041 +++++++++-------- .../test/linker/security_integration_spec.ts | 109 +- .../source_map_integration_node_only_spec.ts | 295 ++--- .../test/render3/view_container_ref_spec.ts | 386 +++--- packages/core/test/view/provider_spec.ts | 85 +- 11 files changed, 1566 insertions(+), 1451 deletions(-) diff --git a/packages/core/test/component_fixture_spec.ts b/packages/core/test/component_fixture_spec.ts index 2256094ee1..6f367e1a74 100644 --- a/packages/core/test/component_fixture_spec.ts +++ b/packages/core/test/component_fixture_spec.ts @@ -84,7 +84,7 @@ class NestedAsyncTimeoutComp { } { - fixmeIvy('unknown') && describe('ComponentFixture', () => { + describe('ComponentFixture', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ @@ -94,7 +94,7 @@ class NestedAsyncTimeoutComp { }); })); - it('should auto detect changes if autoDetectChanges is called', () => { + fixmeIvy('unknown') && it('should auto detect changes if autoDetectChanges is called', () => { const componentFixture = TestBed.createComponent(AutoDetectComp); expect(componentFixture.ngZone).not.toBeNull(); @@ -108,181 +108,192 @@ class NestedAsyncTimeoutComp { expect(componentFixture.nativeElement).toHaveText('11'); }); - it('should auto detect changes if ComponentFixtureAutoDetect is provided as true', - withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => { + fixmeIvy('unknown') && + it('should auto detect changes if ComponentFixtureAutoDetect is provided as true', + withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => { - const componentFixture = TestBed.createComponent(AutoDetectComp); - expect(componentFixture.nativeElement).toHaveText('1'); + const componentFixture = TestBed.createComponent(AutoDetectComp); + expect(componentFixture.nativeElement).toHaveText('1'); - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); - expect(componentFixture.nativeElement).toHaveText('11'); - })); - - it('should signal through whenStable when the fixture is stable (autoDetectChanges)', - async(() => { - const componentFixture = TestBed.createComponent(AsyncComp); - componentFixture.autoDetectChanges(); - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - expect(componentFixture.nativeElement).toHaveText('1'); - - // Component is updated asynchronously. Wait for the fixture to become stable - // before checking for new value. - expect(componentFixture.isStable()).toBe(false); - componentFixture.whenStable().then((waited) => { - expect(waited).toBe(true); - expect(componentFixture.nativeElement).toHaveText('11'); - }); - })); - - it('should signal through isStable when the fixture is stable (no autoDetectChanges)', - async(() => { - const componentFixture = TestBed.createComponent(AsyncComp); - - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - expect(componentFixture.nativeElement).toHaveText('1'); - - // Component is updated asynchronously. Wait for the fixture to become stable - // before checking. - componentFixture.whenStable().then((waited) => { - expect(waited).toBe(true); - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('11'); - }); - })); - - it('should wait for macroTask(setTimeout) while checking for whenStable ' + - '(autoDetectChanges)', - async(() => { - const componentFixture = TestBed.createComponent(AsyncTimeoutComp); - componentFixture.autoDetectChanges(); - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - expect(componentFixture.nativeElement).toHaveText('1'); - - // Component is updated asynchronously. Wait for the fixture to become - // stable before checking for new value. - expect(componentFixture.isStable()).toBe(false); - componentFixture.whenStable().then((waited) => { - expect(waited).toBe(true); - expect(componentFixture.nativeElement).toHaveText('11'); - }); - })); - - it('should wait for macroTask(setTimeout) while checking for whenStable ' + - '(no autoDetectChanges)', - async(() => { - - const componentFixture = TestBed.createComponent(AsyncTimeoutComp); - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - expect(componentFixture.nativeElement).toHaveText('1'); - - // Component is updated asynchronously. Wait for the fixture to become - // stable before checking for new value. - expect(componentFixture.isStable()).toBe(false); - componentFixture.whenStable().then((waited) => { - expect(waited).toBe(true); - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('11'); - }); - })); - - it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' + - '(autoDetectChanges)', - async(() => { - - const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp); - - componentFixture.autoDetectChanges(); - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - expect(componentFixture.nativeElement).toHaveText('1'); - - // Component is updated asynchronously. Wait for the fixture to become - // stable before checking for new value. - expect(componentFixture.isStable()).toBe(false); - componentFixture.whenStable().then((waited) => { - expect(waited).toBe(true); - expect(componentFixture.nativeElement).toHaveText('11'); - }); - })); - - it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' + - '(no autoDetectChanges)', - async(() => { - - const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp); - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - expect(componentFixture.nativeElement).toHaveText('1'); - - // Component is updated asynchronously. Wait for the fixture to become - // stable before checking for new value. - expect(componentFixture.isStable()).toBe(false); - componentFixture.whenStable().then((waited) => { - expect(waited).toBe(true); - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('11'); - }); - })); - - it('should stabilize after async task in change detection (autoDetectChanges)', async(() => { - - const componentFixture = TestBed.createComponent(AsyncChangeComp); - - componentFixture.autoDetectChanges(); - componentFixture.whenStable().then((_) => { - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - - componentFixture.whenStable().then( - (_) => { expect(componentFixture.nativeElement).toHaveText('11'); }); - }); - })); - - it('should stabilize after async task in change detection(no autoDetectChanges)', async(() => { - - const componentFixture = TestBed.createComponent(AsyncChangeComp); - componentFixture.detectChanges(); - componentFixture.whenStable().then((_) => { - // Run detectChanges again so that stabilized value is reflected in the - // DOM. - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('1'); - - const element = componentFixture.debugElement.children[0]; - dispatchEvent(element.nativeElement, 'click'); - componentFixture.detectChanges(); - - componentFixture.whenStable().then((_) => { - // Run detectChanges again so that stabilized value is reflected in - // the DOM. - componentFixture.detectChanges(); expect(componentFixture.nativeElement).toHaveText('11'); - }); - }); - })); + })); + + fixmeIvy('unknown') && + it('should signal through whenStable when the fixture is stable (autoDetectChanges)', + async(() => { + const componentFixture = TestBed.createComponent(AsyncComp); + componentFixture.autoDetectChanges(); + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + expect(componentFixture.nativeElement).toHaveText('1'); + + // Component is updated asynchronously. Wait for the fixture to become stable + // before checking for new value. + expect(componentFixture.isStable()).toBe(false); + componentFixture.whenStable().then((waited) => { + expect(waited).toBe(true); + expect(componentFixture.nativeElement).toHaveText('11'); + }); + })); + + fixmeIvy('unknown') && + it('should signal through isStable when the fixture is stable (no autoDetectChanges)', + async(() => { + const componentFixture = TestBed.createComponent(AsyncComp); + + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + expect(componentFixture.nativeElement).toHaveText('1'); + + // Component is updated asynchronously. Wait for the fixture to become stable + // before checking. + componentFixture.whenStable().then((waited) => { + expect(waited).toBe(true); + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('11'); + }); + })); + + fixmeIvy('unknown') && + it('should wait for macroTask(setTimeout) while checking for whenStable ' + + '(autoDetectChanges)', + async(() => { + const componentFixture = TestBed.createComponent(AsyncTimeoutComp); + componentFixture.autoDetectChanges(); + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + expect(componentFixture.nativeElement).toHaveText('1'); + + // Component is updated asynchronously. Wait for the fixture to become + // stable before checking for new value. + expect(componentFixture.isStable()).toBe(false); + componentFixture.whenStable().then((waited) => { + expect(waited).toBe(true); + expect(componentFixture.nativeElement).toHaveText('11'); + }); + })); + + fixmeIvy('unknown') && + it('should wait for macroTask(setTimeout) while checking for whenStable ' + + '(no autoDetectChanges)', + async(() => { + + const componentFixture = TestBed.createComponent(AsyncTimeoutComp); + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + expect(componentFixture.nativeElement).toHaveText('1'); + + // Component is updated asynchronously. Wait for the fixture to become + // stable before checking for new value. + expect(componentFixture.isStable()).toBe(false); + componentFixture.whenStable().then((waited) => { + expect(waited).toBe(true); + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('11'); + }); + })); + + fixmeIvy('unknown') && + it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' + + '(autoDetectChanges)', + async(() => { + + const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp); + + componentFixture.autoDetectChanges(); + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + expect(componentFixture.nativeElement).toHaveText('1'); + + // Component is updated asynchronously. Wait for the fixture to become + // stable before checking for new value. + expect(componentFixture.isStable()).toBe(false); + componentFixture.whenStable().then((waited) => { + expect(waited).toBe(true); + expect(componentFixture.nativeElement).toHaveText('11'); + }); + })); + + fixmeIvy('unknown') && + it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' + + '(no autoDetectChanges)', + async(() => { + + const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp); + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + expect(componentFixture.nativeElement).toHaveText('1'); + + // Component is updated asynchronously. Wait for the fixture to become + // stable before checking for new value. + expect(componentFixture.isStable()).toBe(false); + componentFixture.whenStable().then((waited) => { + expect(waited).toBe(true); + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('11'); + }); + })); + + fixmeIvy('unknown') && + it('should stabilize after async task in change detection (autoDetectChanges)', + async(() => { + + const componentFixture = TestBed.createComponent(AsyncChangeComp); + + componentFixture.autoDetectChanges(); + componentFixture.whenStable().then((_) => { + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + + componentFixture.whenStable().then( + (_) => { expect(componentFixture.nativeElement).toHaveText('11'); }); + }); + })); + + fixmeIvy('unknown') && + it('should stabilize after async task in change detection(no autoDetectChanges)', + async(() => { + + const componentFixture = TestBed.createComponent(AsyncChangeComp); + componentFixture.detectChanges(); + componentFixture.whenStable().then((_) => { + // Run detectChanges again so that stabilized value is reflected in the + // DOM. + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('1'); + + const element = componentFixture.debugElement.children[0]; + dispatchEvent(element.nativeElement, 'click'); + componentFixture.detectChanges(); + + componentFixture.whenStable().then((_) => { + // Run detectChanges again so that stabilized value is reflected in + // the DOM. + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('11'); + }); + }); + })); describe('No NgZone', () => { beforeEach(() => { @@ -290,7 +301,7 @@ class NestedAsyncTimeoutComp { {providers: [{provide: ComponentFixtureNoNgZone, useValue: true}]}); }); - it('calling autoDetectChanges raises an error', () => { + fixmeIvy('unknown') && it('calling autoDetectChanges raises an error', () => { const componentFixture = TestBed.createComponent(SimpleComp); expect(() => { @@ -298,27 +309,28 @@ class NestedAsyncTimeoutComp { }).toThrowError(/Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set/); }); - it('should instantiate a component with valid DOM', async(() => { + fixmeIvy('unknown') && + it('should instantiate a component with valid DOM', async(() => { - const componentFixture = TestBed.createComponent(SimpleComp); + const componentFixture = TestBed.createComponent(SimpleComp); - expect(componentFixture.ngZone).toBeNull(); - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('Original Simple'); - })); + expect(componentFixture.ngZone).toBeNull(); + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('Original Simple'); + })); - it('should allow changing members of the component', async(() => { + fixmeIvy('unknown') && it('should allow changing members of the component', async(() => { - const componentFixture = TestBed.createComponent(MyIfComp); + const componentFixture = TestBed.createComponent(MyIfComp); - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('MyIf()'); + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('MyIf()'); - componentFixture.componentInstance.showMore = true; - componentFixture.detectChanges(); - expect(componentFixture.nativeElement).toHaveText('MyIf(More)'); + componentFixture.componentInstance.showMore = true; + componentFixture.detectChanges(); + expect(componentFixture.nativeElement).toHaveText('MyIf(More)'); - })); + })); }); }); diff --git a/packages/core/test/debug/debug_node_spec.ts b/packages/core/test/debug/debug_node_spec.ts index ab5cf954fe..088243e1e2 100644 --- a/packages/core/test/debug/debug_node_spec.ts +++ b/packages/core/test/debug/debug_node_spec.ts @@ -169,7 +169,7 @@ class TestApp { } { - fixmeIvy('unknown') && describe('debug element', () => { + describe('debug element', () => { let fixture: ComponentFixture; beforeEach(async(() => { @@ -192,13 +192,13 @@ class TestApp { }); })); - it('should list all child nodes', () => { + fixmeIvy('unknown') && it('should list all child nodes', () => { fixture = TestBed.createComponent(ParentComp); fixture.detectChanges(); expect(fixture.debugElement.childNodes.length).toEqual(3); }); - it('should list all component child elements', () => { + fixmeIvy('unknown') && it('should list all component child elements', () => { fixture = TestBed.createComponent(ParentComp); fixture.detectChanges(); const childEls = fixture.debugElement.children; @@ -225,7 +225,7 @@ class TestApp { expect(getDOM().hasClass(childNested[0].nativeElement, 'childnested')).toBe(true); }); - it('should list conditional component child elements', () => { + fixmeIvy('unknown') && it('should list conditional component child elements', () => { fixture = TestBed.createComponent(ConditionalParentComp); fixture.detectChanges(); @@ -246,7 +246,7 @@ class TestApp { expect(conditionalContentComp.children.length).toEqual(1); }); - it('should list child elements within viewports', () => { + fixmeIvy('unknown') && it('should list child elements within viewports', () => { fixture = TestBed.createComponent(UsingFor); fixture.detectChanges(); @@ -259,7 +259,7 @@ class TestApp { expect(list.children.length).toEqual(3); }); - it('should list element attributes', () => { + fixmeIvy('unknown') && it('should list element attributes', () => { fixture = TestBed.createComponent(TestApp); fixture.detectChanges(); const bankElem = fixture.debugElement.children[0]; @@ -268,7 +268,7 @@ class TestApp { expect(bankElem.attributes['account']).toEqual('4747'); }); - it('should list element classes', () => { + fixmeIvy('unknown') && it('should list element classes', () => { fixture = TestBed.createComponent(TestApp); fixture.detectChanges(); const bankElem = fixture.debugElement.children[0]; @@ -277,7 +277,7 @@ class TestApp { expect(bankElem.classes['open']).toBe(false); }); - it('should list element styles', () => { + fixmeIvy('unknown') && it('should list element styles', () => { fixture = TestBed.createComponent(TestApp); fixture.detectChanges(); const bankElem = fixture.debugElement.children[0]; @@ -286,7 +286,7 @@ class TestApp { expect(bankElem.styles['color']).toEqual('red'); }); - it('should query child elements by css', () => { + fixmeIvy('unknown') && it('should query child elements by css', () => { fixture = TestBed.createComponent(ParentComp); fixture.detectChanges(); @@ -296,7 +296,7 @@ class TestApp { expect(getDOM().hasClass(childTestEls[0].nativeElement, 'child-comp-class')).toBe(true); }); - it('should query child elements by directive', () => { + fixmeIvy('unknown') && it('should query child elements by directive', () => { fixture = TestBed.createComponent(ParentComp); fixture.detectChanges(); @@ -309,21 +309,21 @@ class TestApp { expect(getDOM().hasClass(childTestEls[3].nativeElement, 'childnested')).toBe(true); }); - it('should list providerTokens', () => { + fixmeIvy('unknown') && it('should list providerTokens', () => { fixture = TestBed.createComponent(ParentComp); fixture.detectChanges(); expect(fixture.debugElement.providerTokens).toContain(Logger); }); - it('should list locals', () => { + fixmeIvy('unknown') && it('should list locals', () => { fixture = TestBed.createComponent(LocalsComp); fixture.detectChanges(); expect(fixture.debugElement.children[0].references !['alice']).toBeAnInstanceOf(MyDir); }); - it('should allow injecting from the element injector', () => { + fixmeIvy('unknown') && it('should allow injecting from the element injector', () => { fixture = TestBed.createComponent(ParentComp); fixture.detectChanges(); @@ -332,7 +332,7 @@ class TestApp { ]); }); - it('should list event listeners', () => { + fixmeIvy('unknown') && it('should list event listeners', () => { fixture = TestBed.createComponent(EventsComp); fixture.detectChanges(); @@ -341,7 +341,7 @@ class TestApp { }); - it('should trigger event handlers', () => { + fixmeIvy('unknown') && it('should trigger event handlers', () => { fixture = TestBed.createComponent(EventsComp); fixture.detectChanges(); diff --git a/packages/core/test/directive_lifecycle_integration_spec.ts b/packages/core/test/directive_lifecycle_integration_spec.ts index 1369167c30..e1a1e3b0bd 100644 --- a/packages/core/test/directive_lifecycle_integration_spec.ts +++ b/packages/core/test/directive_lifecycle_integration_spec.ts @@ -13,7 +13,7 @@ import {Log} from '@angular/core/testing/src/testing_internal'; import {fixmeIvy} from '@angular/private/testing'; { - fixmeIvy('unknown') && describe('directive lifecycle integration spec', () => { + describe('directive lifecycle integration spec', () => { let log: Log; beforeEach(() => { @@ -31,22 +31,23 @@ import {fixmeIvy} from '@angular/private/testing'; beforeEach(inject([Log], (_log: any) => { log = _log; })); - it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked', - () => { - const fixture = TestBed.createComponent(MyComp5); - fixture.detectChanges(); + fixmeIvy('unknown') && + it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked', + () => { + const fixture = TestBed.createComponent(MyComp5); + fixture.detectChanges(); - expect(log.result()) - .toEqual( - 'ngOnChanges; ngOnInit; ngDoCheck; ngAfterContentInit; ngAfterContentChecked; child_ngDoCheck; ' + - 'ngAfterViewInit; ngAfterViewChecked'); + expect(log.result()) + .toEqual( + 'ngOnChanges; ngOnInit; ngDoCheck; ngAfterContentInit; ngAfterContentChecked; child_ngDoCheck; ' + + 'ngAfterViewInit; ngAfterViewChecked'); - log.clear(); - fixture.detectChanges(); + log.clear(); + fixture.detectChanges(); - expect(log.result()) - .toEqual('ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked'); - }); + expect(log.result()) + .toEqual('ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked'); + }); }); } diff --git a/packages/core/test/fake_async_spec.ts b/packages/core/test/fake_async_spec.ts index a086831a52..009d72dd55 100644 --- a/packages/core/test/fake_async_spec.ts +++ b/packages/core/test/fake_async_spec.ts @@ -18,32 +18,33 @@ const resolvedPromise = Promise.resolve(null); const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec']; { - fixmeIvy('unknown') && describe('fake async', () => { - it('should run synchronous code', () => { + describe('fake async', () => { + fixmeIvy('unknown') && it('should run synchronous code', () => { let ran = false; fakeAsync(() => { ran = true; })(); expect(ran).toEqual(true); }); - it('should pass arguments to the wrapped function', () => { + fixmeIvy('unknown') && it('should pass arguments to the wrapped function', () => { fakeAsync((foo: any /** TODO #9100 */, bar: any /** TODO #9100 */) => { expect(foo).toEqual('foo'); expect(bar).toEqual('bar'); })('foo', 'bar'); }); - it('should work with inject()', fakeAsync(inject([Parser], (parser: any /** TODO #9100 */) => { - expect(parser).toBeAnInstanceOf(Parser); - }))); + fixmeIvy('unknown') && it('should work with inject()', + fakeAsync(inject([Parser], (parser: any /** TODO #9100 */) => { + expect(parser).toBeAnInstanceOf(Parser); + }))); - it('should throw on nested calls', () => { + fixmeIvy('unknown') && it('should throw on nested calls', () => { expect(() => { fakeAsync(() => { fakeAsync((): any /** TODO #9100 */ => null)(); })(); }).toThrowError('fakeAsync() calls can not be nested'); }); - it('should flush microtasks before returning', () => { + fixmeIvy('unknown') && it('should flush microtasks before returning', () => { let thenRan = false; fakeAsync(() => { resolvedPromise.then(_ => { thenRan = true; }); })(); @@ -52,275 +53,280 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec' }); - it('should propagate the return value', - () => { expect(fakeAsync(() => 'foo')()).toEqual('foo'); }); + fixmeIvy('unknown') && it('should propagate the return value', + () => { expect(fakeAsync(() => 'foo')()).toEqual('foo'); }); describe('Promise', () => { - it('should run asynchronous code', fakeAsync(() => { - let thenRan = false; - resolvedPromise.then((_) => { thenRan = true; }); + fixmeIvy('unknown') && it('should run asynchronous code', fakeAsync(() => { + let thenRan = false; + resolvedPromise.then((_) => { thenRan = true; }); - expect(thenRan).toEqual(false); + expect(thenRan).toEqual(false); - flushMicrotasks(); - expect(thenRan).toEqual(true); - })); + flushMicrotasks(); + expect(thenRan).toEqual(true); + })); - it('should run chained thens', fakeAsync(() => { - const log = new Log(); + fixmeIvy('unknown') && it('should run chained thens', fakeAsync(() => { + const log = new Log(); - resolvedPromise.then((_) => log.add(1)).then((_) => log.add(2)); + resolvedPromise.then((_) => log.add(1)).then((_) => log.add(2)); - expect(log.result()).toEqual(''); + expect(log.result()).toEqual(''); - flushMicrotasks(); - expect(log.result()).toEqual('1; 2'); - })); + flushMicrotasks(); + expect(log.result()).toEqual('1; 2'); + })); - it('should run Promise created in Promise', fakeAsync(() => { - const log = new Log(); + fixmeIvy('unknown') && it('should run Promise created in Promise', fakeAsync(() => { + const log = new Log(); - resolvedPromise.then((_) => { - log.add(1); - resolvedPromise.then((_) => log.add(2)); - }); + resolvedPromise.then((_) => { + log.add(1); + resolvedPromise.then((_) => log.add(2)); + }); - expect(log.result()).toEqual(''); + expect(log.result()).toEqual(''); - flushMicrotasks(); - expect(log.result()).toEqual('1; 2'); - })); + flushMicrotasks(); + expect(log.result()).toEqual('1; 2'); + })); - it('should complain if the test throws an exception during async calls', () => { - expect(() => { - fakeAsync(() => { - resolvedPromise.then((_) => { throw new Error('async'); }); - flushMicrotasks(); - })(); - }).toThrowError(/Uncaught \(in promise\): Error: async/); - }); + fixmeIvy('unknown') && + it('should complain if the test throws an exception during async calls', () => { + expect(() => { + fakeAsync(() => { + resolvedPromise.then((_) => { throw new Error('async'); }); + flushMicrotasks(); + })(); + }).toThrowError(/Uncaught \(in promise\): Error: async/); + }); - it('should complain if a test throws an exception', () => { + fixmeIvy('unknown') && it('should complain if a test throws an exception', () => { expect(() => { fakeAsync(() => { throw new Error('sync'); })(); }).toThrowError('sync'); }); }); describe('timers', () => { - it('should run queued zero duration timer on zero tick', fakeAsync(() => { - let ran = false; - setTimeout(() => { ran = true; }, 0); + fixmeIvy('unknown') && + it('should run queued zero duration timer on zero tick', fakeAsync(() => { + let ran = false; + setTimeout(() => { ran = true; }, 0); - expect(ran).toEqual(false); + expect(ran).toEqual(false); - tick(); - expect(ran).toEqual(true); - })); + tick(); + expect(ran).toEqual(true); + })); - it('should run queued timer after sufficient clock ticks', fakeAsync(() => { - let ran = false; - setTimeout(() => { ran = true; }, 10); + fixmeIvy('unknown') && + it('should run queued timer after sufficient clock ticks', fakeAsync(() => { + let ran = false; + setTimeout(() => { ran = true; }, 10); - tick(6); - expect(ran).toEqual(false); + tick(6); + expect(ran).toEqual(false); - tick(6); - expect(ran).toEqual(true); - })); + tick(6); + expect(ran).toEqual(true); + })); - it('should run queued timer only once', fakeAsync(() => { - let cycles = 0; - setTimeout(() => { cycles++; }, 10); + fixmeIvy('unknown') && it('should run queued timer only once', fakeAsync(() => { + let cycles = 0; + setTimeout(() => { cycles++; }, 10); - tick(10); - expect(cycles).toEqual(1); + tick(10); + expect(cycles).toEqual(1); - tick(10); - expect(cycles).toEqual(1); + tick(10); + expect(cycles).toEqual(1); - tick(10); - expect(cycles).toEqual(1); - })); + tick(10); + expect(cycles).toEqual(1); + })); - it('should not run cancelled timer', fakeAsync(() => { - let ran = false; - const id = setTimeout(() => { ran = true; }, 10); - clearTimeout(id); + fixmeIvy('unknown') && it('should not run cancelled timer', fakeAsync(() => { + let ran = false; + const id = setTimeout(() => { ran = true; }, 10); + clearTimeout(id); - tick(10); - expect(ran).toEqual(false); - })); + tick(10); + expect(ran).toEqual(false); + })); - it('should throw an error on dangling timers', () => { + fixmeIvy('unknown') && it('should throw an error on dangling timers', () => { expect(() => { fakeAsync(() => { setTimeout(() => {}, 10); })(); }).toThrowError('1 timer(s) still in the queue.'); }); - it('should throw an error on dangling periodic timers', () => { + fixmeIvy('unknown') && it('should throw an error on dangling periodic timers', () => { expect(() => { fakeAsync(() => { setInterval(() => {}, 10); })(); }).toThrowError('1 periodic timer(s) still in the queue.'); }); - it('should run periodic timers', fakeAsync(() => { - let cycles = 0; - const id = setInterval(() => { cycles++; }, 10); + fixmeIvy('unknown') && it('should run periodic timers', fakeAsync(() => { + let cycles = 0; + const id = setInterval(() => { cycles++; }, 10); - tick(10); - expect(cycles).toEqual(1); + tick(10); + expect(cycles).toEqual(1); - tick(10); - expect(cycles).toEqual(2); + tick(10); + expect(cycles).toEqual(2); - tick(10); - expect(cycles).toEqual(3); - clearInterval(id); - })); + tick(10); + expect(cycles).toEqual(3); + clearInterval(id); + })); - it('should not run cancelled periodic timer', fakeAsync(() => { - let ran = false; - const id = setInterval(() => { ran = true; }, 10); - clearInterval(id); + fixmeIvy('unknown') && it('should not run cancelled periodic timer', fakeAsync(() => { + let ran = false; + const id = setInterval(() => { ran = true; }, 10); + clearInterval(id); - tick(10); - expect(ran).toEqual(false); - })); + tick(10); + expect(ran).toEqual(false); + })); - it('should be able to cancel periodic timers from a callback', fakeAsync(() => { - let cycles = 0; - let id: any /** TODO #9100 */; + fixmeIvy('unknown') && + it('should be able to cancel periodic timers from a callback', fakeAsync(() => { + let cycles = 0; + let id: any /** TODO #9100 */; - id = setInterval(() => { - cycles++; - clearInterval(id); - }, 10); + id = setInterval(() => { + cycles++; + clearInterval(id); + }, 10); - tick(10); - expect(cycles).toEqual(1); + tick(10); + expect(cycles).toEqual(1); - tick(10); - expect(cycles).toEqual(1); - })); + tick(10); + expect(cycles).toEqual(1); + })); - it('should clear periodic timers', fakeAsync(() => { - let cycles = 0; - const id = setInterval(() => { cycles++; }, 10); + fixmeIvy('unknown') && it('should clear periodic timers', fakeAsync(() => { + let cycles = 0; + const id = setInterval(() => { cycles++; }, 10); - tick(10); - expect(cycles).toEqual(1); + tick(10); + expect(cycles).toEqual(1); - discardPeriodicTasks(); + discardPeriodicTasks(); - // Tick once to clear out the timer which already started. - tick(10); - expect(cycles).toEqual(2); + // Tick once to clear out the timer which already started. + tick(10); + expect(cycles).toEqual(2); - tick(10); - // Nothing should change - expect(cycles).toEqual(2); - })); + tick(10); + // Nothing should change + expect(cycles).toEqual(2); + })); - it('should process microtasks before timers', fakeAsync(() => { - const log = new Log(); + fixmeIvy('unknown') && it('should process microtasks before timers', fakeAsync(() => { + const log = new Log(); - resolvedPromise.then((_) => log.add('microtask')); + resolvedPromise.then((_) => log.add('microtask')); - setTimeout(() => log.add('timer'), 9); + setTimeout(() => log.add('timer'), 9); - const id = setInterval(() => log.add('periodic timer'), 10); + const id = setInterval(() => log.add('periodic timer'), 10); - expect(log.result()).toEqual(''); + expect(log.result()).toEqual(''); - tick(10); - expect(log.result()).toEqual('microtask; timer; periodic timer'); - clearInterval(id); - })); + tick(10); + expect(log.result()).toEqual('microtask; timer; periodic timer'); + clearInterval(id); + })); - it('should process micro-tasks created in timers before next timers', fakeAsync(() => { - const log = new Log(); + fixmeIvy('unknown') && + it('should process micro-tasks created in timers before next timers', fakeAsync(() => { + const log = new Log(); - resolvedPromise.then((_) => log.add('microtask')); + resolvedPromise.then((_) => log.add('microtask')); - setTimeout(() => { - log.add('timer'); - resolvedPromise.then((_) => log.add('t microtask')); - }, 9); + setTimeout(() => { + log.add('timer'); + resolvedPromise.then((_) => log.add('t microtask')); + }, 9); - const id = setInterval(() => { - log.add('periodic timer'); - resolvedPromise.then((_) => log.add('pt microtask')); - }, 10); + const id = setInterval(() => { + log.add('periodic timer'); + resolvedPromise.then((_) => log.add('pt microtask')); + }, 10); - tick(10); - expect(log.result()) - .toEqual('microtask; timer; t microtask; periodic timer; pt microtask'); + tick(10); + expect(log.result()) + .toEqual('microtask; timer; t microtask; periodic timer; pt microtask'); - tick(10); - expect(log.result()) - .toEqual( - 'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask'); - clearInterval(id); - })); + tick(10); + expect(log.result()) + .toEqual( + 'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask'); + clearInterval(id); + })); - it('should flush tasks', fakeAsync(() => { - let ran = false; - setTimeout(() => { ran = true; }, 10); + fixmeIvy('unknown') && it('should flush tasks', fakeAsync(() => { + let ran = false; + setTimeout(() => { ran = true; }, 10); - flush(); - expect(ran).toEqual(true); - })); + flush(); + expect(ran).toEqual(true); + })); - it('should flush multiple tasks', fakeAsync(() => { - let ran = false; - let ran2 = false; - setTimeout(() => { ran = true; }, 10); - setTimeout(() => { ran2 = true; }, 30); + fixmeIvy('unknown') && it('should flush multiple tasks', fakeAsync(() => { + let ran = false; + let ran2 = false; + setTimeout(() => { ran = true; }, 10); + setTimeout(() => { ran2 = true; }, 30); - let elapsed = flush(); + let elapsed = flush(); - expect(ran).toEqual(true); - expect(ran2).toEqual(true); - expect(elapsed).toEqual(30); - })); + expect(ran).toEqual(true); + expect(ran2).toEqual(true); + expect(elapsed).toEqual(30); + })); - it('should move periodic tasks', fakeAsync(() => { - let ran = false; - let count = 0; - setInterval(() => { count++; }, 10); - setTimeout(() => { ran = true; }, 35); + fixmeIvy('unknown') && it('should move periodic tasks', fakeAsync(() => { + let ran = false; + let count = 0; + setInterval(() => { count++; }, 10); + setTimeout(() => { ran = true; }, 35); - let elapsed = flush(); + let elapsed = flush(); - expect(count).toEqual(3); - expect(ran).toEqual(true); - expect(elapsed).toEqual(35); + expect(count).toEqual(3); + expect(ran).toEqual(true); + expect(elapsed).toEqual(35); - discardPeriodicTasks(); - })); + discardPeriodicTasks(); + })); }); describe('outside of the fakeAsync zone', () => { - it('calling flushMicrotasks should throw', () => { + fixmeIvy('unknown') && it('calling flushMicrotasks should throw', () => { expect(() => { flushMicrotasks(); }).toThrowError('The code should be running in the fakeAsync zone to call this function'); }); - it('calling tick should throw', () => { + fixmeIvy('unknown') && it('calling tick should throw', () => { expect(() => { tick(); }).toThrowError('The code should be running in the fakeAsync zone to call this function'); }); - it('calling flush should throw', () => { + fixmeIvy('unknown') && it('calling flush should throw', () => { expect(() => { flush(); }).toThrowError('The code should be running in the fakeAsync zone to call this function'); }); - it('calling discardPeriodicTasks should throw', () => { + fixmeIvy('unknown') && it('calling discardPeriodicTasks should throw', () => { expect(() => { discardPeriodicTasks(); }).toThrowError('The code should be running in the fakeAsync zone to call this function'); @@ -332,10 +338,10 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec' let zoneInTest1: Zone; beforeEach(fakeAsync(() => { zoneInBeforeEach = Zone.current; })); - it('should use the same zone as in beforeEach', fakeAsync(() => { - zoneInTest1 = Zone.current; - expect(zoneInTest1).toBe(zoneInBeforeEach); - })); + fixmeIvy('unknown') && it('should use the same zone as in beforeEach', fakeAsync(() => { + zoneInTest1 = Zone.current; + expect(zoneInTest1).toBe(zoneInBeforeEach); + })); }); }); @@ -344,19 +350,21 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec' afterEach(() => { ProxyZoneSpec.assertPresent(); }); - it('should allow fakeAsync zone to retroactively set a zoneSpec outside of fakeAsync', () => { - ProxyZoneSpec.assertPresent(); - let state: string = 'not run'; - const testZone = Zone.current.fork({name: 'test-zone'}); - (fakeAsync(() => { - testZone.run(() => { - Promise.resolve('works').then((v) => state = v); - expect(state).toEqual('not run'); - flushMicrotasks(); - expect(state).toEqual('works'); - }); - }))(); - expect(state).toEqual('works'); - }); + fixmeIvy('unknown') && + it('should allow fakeAsync zone to retroactively set a zoneSpec outside of fakeAsync', + () => { + ProxyZoneSpec.assertPresent(); + let state: string = 'not run'; + const testZone = Zone.current.fork({name: 'test-zone'}); + (fakeAsync(() => { + testZone.run(() => { + Promise.resolve('works').then((v) => state = v); + expect(state).toEqual('not run'); + flushMicrotasks(); + expect(state).toEqual('works'); + }); + }))(); + expect(state).toEqual('works'); + }); }); } diff --git a/packages/core/test/forward_ref_integration_spec.ts b/packages/core/test/forward_ref_integration_spec.ts index 296c8b4d7e..64e18f5c86 100644 --- a/packages/core/test/forward_ref_integration_spec.ts +++ b/packages/core/test/forward_ref_integration_spec.ts @@ -13,15 +13,17 @@ import {expect} from '@angular/platform-browser/testing/src/matchers'; import {fixmeIvy} from '@angular/private/testing'; { - fixmeIvy('unknown') && describe('forwardRef integration', function() { + describe('forwardRef integration', function() { beforeEach(() => { TestBed.configureTestingModule({imports: [Module], declarations: [App]}); }); - it('should instantiate components which are declared using forwardRef', () => { - const a = TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}).createComponent(App); - a.detectChanges(); - expect(asNativeElements(a.debugElement.children)).toHaveText('frame(lock)'); - expect(TestBed.get(ModuleFrame)).toBeDefined(); - }); + fixmeIvy('unknown') && + it('should instantiate components which are declared using forwardRef', () => { + const a = + TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}).createComponent(App); + a.detectChanges(); + expect(asNativeElements(a.debugElement.children)).toHaveText('frame(lock)'); + expect(TestBed.get(ModuleFrame)).toBeDefined(); + }); }); } diff --git a/packages/core/test/linker/jit_summaries_integration_spec.ts b/packages/core/test/linker/jit_summaries_integration_spec.ts index bebe685ff7..2716bb8ed5 100644 --- a/packages/core/test/linker/jit_summaries_integration_spec.ts +++ b/packages/core/test/linker/jit_summaries_integration_spec.ts @@ -16,7 +16,7 @@ import {fixmeIvy} from '@angular/private/testing'; { // ivy fix in https://github.com/angular/angular/pull/26871 - fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && describe('Jit Summaries', () => { + describe('Jit Summaries', () => { let instances: Map; let summaries: () => any[]; @@ -138,146 +138,160 @@ import {fixmeIvy} from '@angular/private/testing'; afterEach(() => { resetTestEnvironmentWithSummaries(); }); - it('should use directive metadata from summaries', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should use directive metadata from summaries', () => { + resetTestEnvironmentWithSummaries(summaries); - @Component({template: '
'}) - class TestComp { - } + @Component({template: '
'}) + class TestComp { + } - TestBed - .configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomeDirective]}) - .createComponent(TestComp); - expectInstanceCreated(SomeDirective); - }); + TestBed + .configureTestingModule( + {providers: [SomeDep], declarations: [TestComp, SomeDirective]}) + .createComponent(TestComp); + expectInstanceCreated(SomeDirective); + }); - it('should use pipe metadata from summaries', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should use pipe metadata from summaries', () => { + resetTestEnvironmentWithSummaries(summaries); - @Component({template: '{{1 | somePipe}}'}) - class TestComp { - } + @Component({template: '{{1 | somePipe}}'}) + class TestComp { + } - TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomePipe]}) - .createComponent(TestComp); - expectInstanceCreated(SomePipe); - }); + TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomePipe]}) + .createComponent(TestComp); + expectInstanceCreated(SomePipe); + }); - it('should use Service metadata from summaries', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should use Service metadata from summaries', () => { + resetTestEnvironmentWithSummaries(summaries); - TestBed.configureTestingModule({ - providers: [SomeService, SomeDep], - }); - TestBed.get(SomeService); - expectInstanceCreated(SomeService); - }); + TestBed.configureTestingModule({ + providers: [SomeService, SomeDep], + }); + TestBed.get(SomeService); + expectInstanceCreated(SomeService); + }); - it('should use NgModule metadata from summaries', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should use NgModule metadata from summaries', () => { + resetTestEnvironmentWithSummaries(summaries); - TestBed - .configureTestingModule( - {providers: [SomeDep], declarations: [TestComp3], imports: [SomeModule]}) - .createComponent(TestComp3); + TestBed + .configureTestingModule( + {providers: [SomeDep], declarations: [TestComp3], imports: [SomeModule]}) + .createComponent(TestComp3); - expectInstanceCreated(SomeModule); - expectInstanceCreated(SomeDirective); - expectInstanceCreated(SomePipe); - expectInstanceCreated(SomeService); - }); + expectInstanceCreated(SomeModule); + expectInstanceCreated(SomeDirective); + expectInstanceCreated(SomePipe); + expectInstanceCreated(SomeService); + }); - it('should allow to create private components from imported NgModule summaries', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should allow to create private components from imported NgModule summaries', () => { + resetTestEnvironmentWithSummaries(summaries); - TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]}) - .createComponent(SomePrivateComponent); - expectInstanceCreated(SomePrivateComponent); - }); + TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]}) + .createComponent(SomePrivateComponent); + expectInstanceCreated(SomePrivateComponent); + }); - it('should throw when trying to mock a type with a summary', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should throw when trying to mock a type with a summary', () => { + resetTestEnvironmentWithSummaries(summaries); - TestBed.resetTestingModule(); - expect(() => TestBed.overrideComponent(SomePrivateComponent, {add: {}}).compileComponents()) - .toThrowError( - 'SomePrivateComponent was AOT compiled, so its metadata cannot be changed.'); - TestBed.resetTestingModule(); - expect(() => TestBed.overrideDirective(SomeDirective, {add: {}}).compileComponents()) - .toThrowError('SomeDirective was AOT compiled, so its metadata cannot be changed.'); - TestBed.resetTestingModule(); - expect(() => TestBed.overridePipe(SomePipe, {add: {name: 'test'}}).compileComponents()) - .toThrowError('SomePipe was AOT compiled, so its metadata cannot be changed.'); - TestBed.resetTestingModule(); - expect(() => TestBed.overrideModule(SomeModule, {add: {}}).compileComponents()) - .toThrowError('SomeModule was AOT compiled, so its metadata cannot be changed.'); - }); + TestBed.resetTestingModule(); + expect( + () => TestBed.overrideComponent(SomePrivateComponent, {add: {}}).compileComponents()) + .toThrowError( + 'SomePrivateComponent was AOT compiled, so its metadata cannot be changed.'); + TestBed.resetTestingModule(); + expect(() => TestBed.overrideDirective(SomeDirective, {add: {}}).compileComponents()) + .toThrowError('SomeDirective was AOT compiled, so its metadata cannot be changed.'); + TestBed.resetTestingModule(); + expect(() => TestBed.overridePipe(SomePipe, {add: {name: 'test'}}).compileComponents()) + .toThrowError('SomePipe was AOT compiled, so its metadata cannot be changed.'); + TestBed.resetTestingModule(); + expect(() => TestBed.overrideModule(SomeModule, {add: {}}).compileComponents()) + .toThrowError('SomeModule was AOT compiled, so its metadata cannot be changed.'); + }); - it('should return stack trace and component data on resetTestingModule when error is thrown', - () => { - resetTestEnvironmentWithSummaries(); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should return stack trace and component data on resetTestingModule when error is thrown', + () => { + resetTestEnvironmentWithSummaries(); - const fixture = TestBed.configureTestingModule({declarations: [TestCompErrorOnDestroy]}) - .createComponent(TestCompErrorOnDestroy); + const fixture = + TestBed.configureTestingModule({declarations: [TestCompErrorOnDestroy]}) + .createComponent(TestCompErrorOnDestroy); - const expectedError = 'Error from ngOnDestroy'; + const expectedError = 'Error from ngOnDestroy'; - const component: TestCompErrorOnDestroy = fixture.componentInstance; + const component: TestCompErrorOnDestroy = fixture.componentInstance; - spyOn(console, 'error'); - spyOn(component, 'ngOnDestroy').and.throwError(expectedError); + spyOn(console, 'error'); + spyOn(component, 'ngOnDestroy').and.throwError(expectedError); - const expectedObject = { - stacktrace: new Error(expectedError), - component, - }; + const expectedObject = { + stacktrace: new Error(expectedError), + component, + }; - TestBed.resetTestingModule(); + TestBed.resetTestingModule(); - expect(console.error) - .toHaveBeenCalledWith('Error during cleanup of component', expectedObject); - }); + expect(console.error) + .toHaveBeenCalledWith('Error during cleanup of component', expectedObject); + }); - it('should allow to add summaries via configureTestingModule', () => { - resetTestEnvironmentWithSummaries(); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should allow to add summaries via configureTestingModule', () => { + resetTestEnvironmentWithSummaries(); - @Component({template: '
'}) - class TestComp { - } + @Component({template: '
'}) + class TestComp { + } - TestBed - .configureTestingModule({ - providers: [SomeDep], - declarations: [TestComp, SomeDirective], - aotSummaries: summaries - }) - .createComponent(TestComp); - expectInstanceCreated(SomeDirective); - }); + TestBed + .configureTestingModule({ + providers: [SomeDep], + declarations: [TestComp, SomeDirective], + aotSummaries: summaries + }) + .createComponent(TestComp); + expectInstanceCreated(SomeDirective); + }); - it('should allow to override a provider', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should allow to override a provider', () => { + resetTestEnvironmentWithSummaries(summaries); - const overwrittenValue = {}; + const overwrittenValue = {}; - const fixture = - TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []}) - .configureTestingModule({providers: [SomeDep], imports: [SomeModule]}) - .createComponent(SomePublicComponent); + const fixture = + TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []}) + .configureTestingModule({providers: [SomeDep], imports: [SomeModule]}) + .createComponent(SomePublicComponent); - expect(fixture.componentInstance.dep).toBe(overwrittenValue); - }); + expect(fixture.componentInstance.dep).toBe(overwrittenValue); + }); - it('should allow to override a template', () => { - resetTestEnvironmentWithSummaries(summaries); + fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && + it('should allow to override a template', () => { + resetTestEnvironmentWithSummaries(summaries); - TestBed.overrideTemplateUsingTestingModule(SomePublicComponent, 'overwritten'); + TestBed.overrideTemplateUsingTestingModule(SomePublicComponent, 'overwritten'); - const fixture = TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]}) - .createComponent(SomePublicComponent); - expectInstanceCreated(SomePublicComponent); + const fixture = + TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]}) + .createComponent(SomePublicComponent); + expectInstanceCreated(SomePublicComponent); - expect(fixture.nativeElement).toHaveText('overwritten'); - }); + expect(fixture.nativeElement).toHaveText('overwritten'); + }); }); } diff --git a/packages/core/test/linker/query_integration_spec.ts b/packages/core/test/linker/query_integration_spec.ts index 17ba44ff88..ea650c1fc9 100644 --- a/packages/core/test/linker/query_integration_spec.ts +++ b/packages/core/test/linker/query_integration_spec.ts @@ -15,7 +15,7 @@ import {Subject} from 'rxjs'; import {stringify} from '../../src/util'; // FW-670: Internal Error: The name q is already defined in scope -fixmeIvy('FW-670') && describe('Query API', () => { +describe('Query API', () => { beforeEach(() => TestBed.configureTestingModule({ declarations: [ @@ -54,530 +54,582 @@ fixmeIvy('FW-670') && describe('Query API', () => { })); describe('querying by directive type', () => { - it('should contain all direct child directives in the light dom (constructor)', () => { - const template = '
' + - '
' + - '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all direct child directives in the light dom (constructor)', () => { + const template = '
' + + '
' + + '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|'); - }); + expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|'); + }); - it('should contain all direct child directives in the content dom', () => { - const template = '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all direct child directives in the content dom', () => { + const template = + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; - view.detectChanges(); - expect(q.textDirChildren.length).toEqual(1); - expect(q.numberOfChildrenAfterContentInit).toEqual(1); - }); + const q = view.debugElement.children[0].references !['q']; + view.detectChanges(); + expect(q.textDirChildren.length).toEqual(1); + expect(q.numberOfChildrenAfterContentInit).toEqual(1); + }); - it('should contain the first content child', () => { - const template = - '
'; - const view = createTestCmp(MyComp0, template); - view.componentInstance.shouldShow = true; - view.detectChanges(); - const q: NeedsContentChild = view.debugElement.children[0].references !['q']; - expect(q.logs).toEqual([['setter', 'foo'], ['init', 'foo'], ['check', 'foo']]); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first content child', () => { + const template = + '
'; + const view = createTestCmp(MyComp0, template); + view.componentInstance.shouldShow = true; + view.detectChanges(); + const q: NeedsContentChild = view.debugElement.children[0].references !['q']; + expect(q.logs).toEqual([['setter', 'foo'], ['init', 'foo'], ['check', 'foo']]); - view.componentInstance.shouldShow = false; - view.detectChanges(); - expect(q.logs).toEqual([ - ['setter', 'foo'], ['init', 'foo'], ['check', 'foo'], ['setter', null], ['check', null] - ]); - }); + view.componentInstance.shouldShow = false; + view.detectChanges(); + expect(q.logs).toEqual([ + ['setter', 'foo'], ['init', 'foo'], ['check', 'foo'], ['setter', null], + ['check', null] + ]); + }); - it('should contain the first content child when target is on with embedded view (issue #16568)', - () => { - const template = - '
' + - '
'; - const view = createTestCmp(MyComp0, template); - view.detectChanges(); - const q: NeedsContentChild = view.debugElement.children[1].references !['q']; - expect(q.child.text).toEqual('foo'); - const directive: DirectiveNeedsContentChild = - view.debugElement.children[0].injector.get(DirectiveNeedsContentChild); - expect(directive.child.text).toEqual('foo'); - }); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first content child when target is on with embedded view (issue #16568)', + () => { + const template = + '
' + + '
'; + const view = createTestCmp(MyComp0, template); + view.detectChanges(); + const q: NeedsContentChild = view.debugElement.children[1].references !['q']; + expect(q.child.text).toEqual('foo'); + const directive: DirectiveNeedsContentChild = + view.debugElement.children[0].injector.get(DirectiveNeedsContentChild); + expect(directive.child.text).toEqual('foo'); + }); - it('should contain the first view child', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first view child', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewChild = view.debugElement.children[0].references !['q']; - expect(q.logs).toEqual([['setter', 'foo'], ['init', 'foo'], ['check', 'foo']]); + const q: NeedsViewChild = view.debugElement.children[0].references !['q']; + expect(q.logs).toEqual([['setter', 'foo'], ['init', 'foo'], ['check', 'foo']]); - q.shouldShow = false; - view.detectChanges(); - expect(q.logs).toEqual([ - ['setter', 'foo'], ['init', 'foo'], ['check', 'foo'], ['setter', null], ['check', null] - ]); - }); + q.shouldShow = false; + view.detectChanges(); + expect(q.logs).toEqual([ + ['setter', 'foo'], ['init', 'foo'], ['check', 'foo'], ['setter', null], + ['check', null] + ]); + }); - it('should set static view and content children already after the constructor call', () => { - const template = - '
'; - const view = createTestCmp(MyComp0, template); - const q: NeedsStaticContentAndViewChild = view.debugElement.children[0].references !['q']; - expect(q.contentChild.text).toBeFalsy(); - expect(q.viewChild.text).toBeFalsy(); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should set static view and content children already after the constructor call', () => { + const template = + '
'; + const view = createTestCmp(MyComp0, template); + const q: NeedsStaticContentAndViewChild = view.debugElement.children[0].references !['q']; + expect(q.contentChild.text).toBeFalsy(); + expect(q.viewChild.text).toBeFalsy(); - view.detectChanges(); - expect(q.contentChild.text).toEqual('contentFoo'); - expect(q.viewChild.text).toEqual('viewFoo'); - }); + view.detectChanges(); + expect(q.contentChild.text).toEqual('contentFoo'); + expect(q.viewChild.text).toEqual('viewFoo'); + }); - it('should contain the first view child across embedded views', () => { - TestBed.overrideComponent( - MyComp0, {set: {template: ''}}); - TestBed.overrideComponent(NeedsViewChild, { - set: { - template: - '
' - } - }); - const view = TestBed.createComponent(MyComp0); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first view child across embedded views', () => { + TestBed.overrideComponent( + MyComp0, {set: {template: ''}}); + TestBed.overrideComponent(NeedsViewChild, { + set: { + template: + '
' + } + }); + const view = TestBed.createComponent(MyComp0); - view.detectChanges(); - const q: NeedsViewChild = view.debugElement.children[0].references !['q']; - expect(q.logs).toEqual([['setter', 'foo'], ['init', 'foo'], ['check', 'foo']]); + view.detectChanges(); + const q: NeedsViewChild = view.debugElement.children[0].references !['q']; + expect(q.logs).toEqual([['setter', 'foo'], ['init', 'foo'], ['check', 'foo']]); - q.shouldShow = false; - q.shouldShow2 = true; - q.logs = []; - view.detectChanges(); - expect(q.logs).toEqual([['setter', 'bar'], ['check', 'bar']]); + q.shouldShow = false; + q.shouldShow2 = true; + q.logs = []; + view.detectChanges(); + expect(q.logs).toEqual([['setter', 'bar'], ['check', 'bar']]); - q.shouldShow = false; - q.shouldShow2 = false; - q.logs = []; - view.detectChanges(); - expect(q.logs).toEqual([['setter', null], ['check', null]]); - }); + q.shouldShow = false; + q.shouldShow2 = false; + q.logs = []; + view.detectChanges(); + expect(q.logs).toEqual([['setter', null], ['check', null]]); + }); - it('should contain all directives in the light dom when descendants flag is used', () => { - const template = '
' + - '
' + - '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all directives in the light dom when descendants flag is used', () => { + const template = '
' + + '
' + + '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|4|'); - }); + expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|4|'); + }); - it('should contain all directives in the light dom', () => { - const template = '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all directives in the light dom', () => { + const template = '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|'); - }); + expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|'); + }); - it('should reflect dynamically inserted directives', () => { - const template = '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - expect(asNativeElements(view.debugElement.children)).toHaveText('2|'); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should reflect dynamically inserted directives', () => { + const template = '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + expect(asNativeElements(view.debugElement.children)).toHaveText('2|'); - view.componentInstance.shouldShow = true; - view.detectChanges(); - expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|'); - }); + view.componentInstance.shouldShow = true; + view.detectChanges(); + expect(asNativeElements(view.debugElement.children)).toHaveText('2|3|'); + }); - it('should be cleanly destroyed when a query crosses view boundaries', () => { - const template = '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should be cleanly destroyed when a query crosses view boundaries', () => { + const template = '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - view.componentInstance.shouldShow = true; - view.detectChanges(); - view.destroy(); - }); + view.componentInstance.shouldShow = true; + view.detectChanges(); + view.destroy(); + }); - it('should reflect moved directives', () => { - const template = '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - expect(asNativeElements(view.debugElement.children)).toHaveText('2|1d|2d|3d|'); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should reflect moved directives', () => { + const template = '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + expect(asNativeElements(view.debugElement.children)).toHaveText('2|1d|2d|3d|'); - view.componentInstance.list = ['3d', '2d']; - view.detectChanges(); - expect(asNativeElements(view.debugElement.children)).toHaveText('2|3d|2d|'); - }); + view.componentInstance.list = ['3d', '2d']; + view.detectChanges(); + expect(asNativeElements(view.debugElement.children)).toHaveText('2|3d|2d|'); + }); - it('should throw with descriptive error when query selectors are not present', () => { - TestBed.configureTestingModule({declarations: [MyCompBroken0, HasNullQueryCondition]}); - const template = ''; - TestBed.overrideComponent(MyCompBroken0, {set: {template}}); - expect(() => TestBed.createComponent(MyCompBroken0)) - .toThrowError( - `Can't construct a query for the property "errorTrigger" of "${stringify(HasNullQueryCondition)}" since the query selector wasn't defined.`); - }); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should throw with descriptive error when query selectors are not present', () => { + TestBed.configureTestingModule({declarations: [MyCompBroken0, HasNullQueryCondition]}); + const template = ''; + TestBed.overrideComponent(MyCompBroken0, {set: {template}}); + expect(() => TestBed.createComponent(MyCompBroken0)) + .toThrowError( + `Can't construct a query for the property "errorTrigger" of "${stringify(HasNullQueryCondition)}" since the query selector wasn't defined.`); + }); }); describe('query for TemplateRef', () => { - it('should find TemplateRefs in the light and shadow dom', () => { - const template = '
light
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const needsTpl: NeedsTpl = view.debugElement.children[0].injector.get(NeedsTpl); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should find TemplateRefs in the light and shadow dom', () => { + const template = '
light
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const needsTpl: NeedsTpl = view.debugElement.children[0].injector.get(NeedsTpl); - expect(needsTpl.vc.createEmbeddedView(needsTpl.query.first).rootNodes[0]).toHaveText('light'); - expect(needsTpl.vc.createEmbeddedView(needsTpl.viewQuery.first).rootNodes[0]) - .toHaveText('shadow'); - }); + expect(needsTpl.vc.createEmbeddedView(needsTpl.query.first).rootNodes[0]) + .toHaveText('light'); + expect(needsTpl.vc.createEmbeddedView(needsTpl.viewQuery.first).rootNodes[0]) + .toHaveText('shadow'); + }); - it('should find named TemplateRefs', () => { - const template = - '
light
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const needsTpl: NeedsNamedTpl = view.debugElement.children[0].injector.get(NeedsNamedTpl); - expect(needsTpl.vc.createEmbeddedView(needsTpl.contentTpl).rootNodes[0]).toHaveText('light'); - expect(needsTpl.vc.createEmbeddedView(needsTpl.viewTpl).rootNodes[0]).toHaveText('shadow'); - }); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should find named TemplateRefs', () => { + const template = + '
light
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const needsTpl: NeedsNamedTpl = view.debugElement.children[0].injector.get(NeedsNamedTpl); + expect(needsTpl.vc.createEmbeddedView(needsTpl.contentTpl).rootNodes[0]) + .toHaveText('light'); + expect(needsTpl.vc.createEmbeddedView(needsTpl.viewTpl).rootNodes[0]) + .toHaveText('shadow'); + }); }); describe('read a different token', () => { - it('should contain all content children', () => { - const template = - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all content children', () => { + const template = + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const comp: NeedsContentChildrenWithRead = - view.debugElement.children[0].injector.get(NeedsContentChildrenWithRead); - expect(comp.textDirChildren.map(textDirective => textDirective.text)).toEqual(['ca', 'cb']); - }); + const comp: NeedsContentChildrenWithRead = + view.debugElement.children[0].injector.get(NeedsContentChildrenWithRead); + expect(comp.textDirChildren.map(textDirective => textDirective.text)).toEqual([ + 'ca', 'cb' + ]); + }); - it('should contain the first content child', () => { - const template = - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first content child', () => { + const template = + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const comp: NeedsContentChildWithRead = - view.debugElement.children[0].injector.get(NeedsContentChildWithRead); - expect(comp.textDirChild.text).toEqual('ca'); - }); + const comp: NeedsContentChildWithRead = + view.debugElement.children[0].injector.get(NeedsContentChildWithRead); + expect(comp.textDirChild.text).toEqual('ca'); + }); - it('should contain the first descendant content child', () => { - const template = '' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first descendant content child', () => { + const template = '' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const comp: NeedsContentChildWithRead = - view.debugElement.children[0].injector.get(NeedsContentChildWithRead); - expect(comp.textDirChild.text).toEqual('ca'); - }); + const comp: NeedsContentChildWithRead = + view.debugElement.children[0].injector.get(NeedsContentChildWithRead); + expect(comp.textDirChild.text).toEqual('ca'); + }); - it('should contain the first descendant content child templateRef', () => { - const template = '' + - ''; - const view = createTestCmp(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first descendant content child templateRef', () => { + const template = '' + + ''; + const view = createTestCmp(MyComp0, template); - // can't - // execute - // checkNoChanges - // as - // our - // view - // modifies - // our - // content - // children - // (via - // a - // query). - view.detectChanges(false); - expect(view.nativeElement).toHaveText('OUTER'); - }); + // can't + // execute + // checkNoChanges + // as + // our + // view + // modifies + // our + // content + // children + // (via + // a + // query). + view.detectChanges(false); + expect(view.nativeElement).toHaveText('OUTER'); + }); - it('should contain the first view child', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain the first view child', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const comp: NeedsViewChildWithRead = - view.debugElement.children[0].injector.get(NeedsViewChildWithRead); - expect(comp.textDirChild.text).toEqual('va'); - }); + const comp: NeedsViewChildWithRead = + view.debugElement.children[0].injector.get(NeedsViewChildWithRead); + expect(comp.textDirChild.text).toEqual('va'); + }); - it('should contain all child directives in the view', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all child directives in the view', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const comp: NeedsViewChildrenWithRead = - view.debugElement.children[0].injector.get(NeedsViewChildrenWithRead); - expect(comp.textDirChildren.map(textDirective => textDirective.text)).toEqual(['va', 'vb']); - }); + const comp: NeedsViewChildrenWithRead = + view.debugElement.children[0].injector.get(NeedsViewChildrenWithRead); + expect(comp.textDirChildren.map(textDirective => textDirective.text)).toEqual([ + 'va', 'vb' + ]); + }); - it('should support reading a ViewContainer', () => { - const template = - 'hello'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should support reading a ViewContainer', () => { + const template = + 'hello'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const comp: NeedsViewContainerWithRead = - view.debugElement.children[0].injector.get(NeedsViewContainerWithRead); - comp.createView(); - expect(view.debugElement.children[0].nativeElement).toHaveText('hello'); - }); + const comp: NeedsViewContainerWithRead = + view.debugElement.children[0].injector.get(NeedsViewContainerWithRead); + comp.createView(); + expect(view.debugElement.children[0].nativeElement).toHaveText('hello'); + }); }); describe('changes', () => { - it('should notify query on change', async(() => { - const template = '' + - '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should notify query on change', async(() => { + const template = '' + + '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; + const q = view.debugElement.children[0].references !['q']; - q.query.changes.subscribe({ - next: () => { - expect(q.query.first.text).toEqual('1'); - expect(q.query.last.text).toEqual('2'); - } - }); + q.query.changes.subscribe({ + next: () => { + expect(q.query.first.text).toEqual('1'); + expect(q.query.last.text).toEqual('2'); + } + }); - view.componentInstance.shouldShow = true; - view.detectChanges(); - })); + view.componentInstance.shouldShow = true; + view.detectChanges(); + })); - it('should correctly clean-up when destroyed together with the directives it is querying', - () => { - const template = '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - view.componentInstance.shouldShow = true; - view.detectChanges(); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should correctly clean-up when destroyed together with the directives it is querying', + () => { + const template = + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + view.componentInstance.shouldShow = true; + view.detectChanges(); - let isQueryListCompleted = false; + let isQueryListCompleted = false; - const q: NeedsQuery = view.debugElement.children[0].references !['q']; - const changes = >q.query.changes; - expect(q.query.length).toEqual(1); - expect(changes.closed).toBeFalsy(); - changes.subscribe(() => {}, () => {}, () => { isQueryListCompleted = true; }); + const q: NeedsQuery = view.debugElement.children[0].references !['q']; + const changes = >q.query.changes; + expect(q.query.length).toEqual(1); + expect(changes.closed).toBeFalsy(); + changes.subscribe(() => {}, () => {}, () => { isQueryListCompleted = true; }); - view.componentInstance.shouldShow = false; - view.detectChanges(); - expect(changes.closed).toBeTruthy(); - expect(isQueryListCompleted).toBeTruthy(); + view.componentInstance.shouldShow = false; + view.detectChanges(); + expect(changes.closed).toBeTruthy(); + expect(isQueryListCompleted).toBeTruthy(); - view.componentInstance.shouldShow = true; - view.detectChanges(); - const q2: NeedsQuery = view.debugElement.children[0].references !['q']; + view.componentInstance.shouldShow = true; + view.detectChanges(); + const q2: NeedsQuery = view.debugElement.children[0].references !['q']; - expect(q2.query.length).toEqual(1); - expect(changes.closed).toBeTruthy(); - expect((>q2.query.changes).closed).toBeFalsy(); - }); + expect(q2.query.length).toEqual(1); + expect(changes.closed).toBeTruthy(); + expect((>q2.query.changes).closed).toBeFalsy(); + }); }); describe('querying by var binding', () => { - it('should contain all the child directives in the light dom with the given var binding', - () => { - const template = '' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all the child directives in the light dom with the given var binding', + () => { + const template = '' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; - view.componentInstance.list = ['1d', '2d']; - view.detectChanges(); - expect(q.query.first.text).toEqual('1d'); - expect(q.query.last.text).toEqual('2d'); - }); + view.componentInstance.list = ['1d', '2d']; + view.detectChanges(); + expect(q.query.first.text).toEqual('1d'); + expect(q.query.last.text).toEqual('2d'); + }); - it('should support querying by multiple var bindings', () => { - const template = '' + - '
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should support querying by multiple var bindings', () => { + const template = '' + + '
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; - expect(q.query.first.text).toEqual('one'); - expect(q.query.last.text).toEqual('two'); - }); + expect(q.query.first.text).toEqual('one'); + expect(q.query.last.text).toEqual('two'); + }); - it('should support dynamically inserted directives', () => { - const template = '' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should support dynamically inserted directives', () => { + const template = '' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; - view.componentInstance.list = ['1d', '2d']; - view.detectChanges(); - view.componentInstance.list = ['2d', '1d']; - view.detectChanges(); - expect(q.query.last.text).toEqual('1d'); - }); + view.componentInstance.list = ['1d', '2d']; + view.detectChanges(); + view.componentInstance.list = ['2d', '1d']; + view.detectChanges(); + expect(q.query.last.text).toEqual('1d'); + }); - it('should contain all the elements in the light dom with the given var binding', () => { - const template = '' + - '
' + - '
{{item}}
' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all the elements in the light dom with the given var binding', () => { + const template = '' + + '
' + + '
{{item}}
' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; - view.componentInstance.list = ['1d', '2d']; - view.detectChanges(); - expect(q.query.first.nativeElement).toHaveText('1d'); - expect(q.query.last.nativeElement).toHaveText('2d'); - }); + view.componentInstance.list = ['1d', '2d']; + view.detectChanges(); + expect(q.query.first.nativeElement).toHaveText('1d'); + expect(q.query.last.nativeElement).toHaveText('2d'); + }); - it('should contain all the elements in the light dom even if they get projected', () => { - const template = '' + - '
' + - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all the elements in the light dom even if they get projected', () => { + const template = '' + + '
' + + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - expect(asNativeElements(view.debugElement.children)).toHaveText('hello|world|'); - }); + expect(asNativeElements(view.debugElement.children)).toHaveText('hello|world|'); + }); - it('should support querying the view by using a view query', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should support querying the view by using a view query', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQueryByLabel = view.debugElement.children[0].references !['q']; - expect(q.query.first.nativeElement).toHaveText('text'); - }); + const q: NeedsViewQueryByLabel = view.debugElement.children[0].references !['q']; + expect(q.query.first.nativeElement).toHaveText('text'); + }); - it('should contain all child directives in the view dom', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; - expect(q.textDirChildren.length).toEqual(1); - expect(q.numberOfChildrenAfterViewInit).toEqual(1); - }); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all child directives in the view dom', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; + expect(q.textDirChildren.length).toEqual(1); + expect(q.numberOfChildrenAfterViewInit).toEqual(1); + }); }); describe('querying in the view', () => { - it('should contain all the elements in the view with that have the given directive', () => { - const template = '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQuery = view.debugElement.children[0].references !['q']; - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); - }); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should contain all the elements in the view with that have the given directive', () => { + const template = '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q: NeedsViewQuery = view.debugElement.children[0].references !['q']; + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); + }); - it('should not include directive present on the host element', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQuery = view.debugElement.children[0].references !['q']; - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); - }); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should not include directive present on the host element', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q: NeedsViewQuery = view.debugElement.children[0].references !['q']; + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); + }); - it('should reflect changes in the component', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQueryIf = view.debugElement.children[0].references !['q']; - expect(q.query.length).toBe(0); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should reflect changes in the component', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q: NeedsViewQueryIf = view.debugElement.children[0].references !['q']; + expect(q.query.length).toBe(0); - q.show = true; - view.detectChanges(); - expect(q.query.length).toBe(1); - expect(q.query.first.text).toEqual('1'); - }); + q.show = true; + view.detectChanges(); + expect(q.query.length).toBe(1); + expect(q.query.first.text).toEqual('1'); + }); - it('should not be affected by other changes in the component', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQueryNestedIf = view.debugElement.children[0].references !['q']; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should not be affected by other changes in the component', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q: NeedsViewQueryNestedIf = view.debugElement.children[0].references !['q']; - expect(q.query.length).toEqual(1); - expect(q.query.first.text).toEqual('1'); + expect(q.query.length).toEqual(1); + expect(q.query.first.text).toEqual('1'); - q.show = false; - view.detectChanges(); - expect(q.query.length).toEqual(1); - expect(q.query.first.text).toEqual('1'); - }); + q.show = false; + view.detectChanges(); + expect(q.query.length).toEqual(1); + expect(q.query.first.text).toEqual('1'); + }); - it('should maintain directives in pre-order depth-first DOM order after dynamic insertion', - () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQueryOrder = view.debugElement.children[0].references !['q']; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should maintain directives in pre-order depth-first DOM order after dynamic insertion', + () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q: NeedsViewQueryOrder = view.debugElement.children[0].references !['q']; - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); - q.list = ['-3', '2']; - view.detectChanges(); - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '-3', '2', '4']); - }); + q.list = ['-3', '2']; + view.detectChanges(); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '-3', '2', '4']); + }); - it('should maintain directives in pre-order depth-first DOM order after dynamic insertion', - () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQueryOrderWithParent = view.debugElement.children[0].references !['q']; - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should maintain directives in pre-order depth-first DOM order after dynamic insertion', + () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q: NeedsViewQueryOrderWithParent = + view.debugElement.children[0].references !['q']; + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2', '3', '4']); - q.list = ['-3', '2']; - view.detectChanges(); - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '-3', '2', '4']); - }); + q.list = ['-3', '2']; + view.detectChanges(); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '-3', '2', '4']); + }); - it('should handle long ngFor cycles', () => { - const template = ''; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q: NeedsViewQueryOrder = view.debugElement.children[0].references !['q']; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should handle long ngFor cycles', () => { + const template = ''; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q: NeedsViewQueryOrder = view.debugElement.children[0].references !['q']; - // no - // significance - // to - // 50, - // just - // a - // reasonably - // large - // cycle. - for (let i = 0; i < 50; i++) { - const newString = i.toString(); - q.list = [newString]; - view.detectChanges(); - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', newString, '4']); - } - }); + // no + // significance + // to + // 50, + // just + // a + // reasonably + // large + // cycle. + for (let i = 0; i < 50; i++) { + const newString = i.toString(); + q.list = [newString]; + view.detectChanges(); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', newString, '4']); + } + }); - it('should support more than three queries', () => { - const template = '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; - expect(q.query1).toBeDefined(); - expect(q.query2).toBeDefined(); - expect(q.query3).toBeDefined(); - expect(q.query4).toBeDefined(); - }); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should support more than three queries', () => { + const template = '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; + expect(q.query1).toBeDefined(); + expect(q.query2).toBeDefined(); + expect(q.query3).toBeDefined(); + expect(q.query4).toBeDefined(); + }); }); describe('query over moved templates', () => { - it('should include manually projected templates in queries', () => { - const template = - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; - expect(q.query.length).toBe(0); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should include manually projected templates in queries', () => { + const template = + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; + expect(q.query.length).toBe(0); - q.create(); - view.detectChanges(); - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1']); + q.create(); + view.detectChanges(); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1']); - q.destroy(); - view.detectChanges(); - expect(q.query.length).toBe(0); - }); + q.destroy(); + view.detectChanges(); + expect(q.query.length).toBe(0); + }); // Note: // This @@ -594,87 +646,90 @@ fixmeIvy('FW-670') && describe('Query API', () => { // for // performance // reasons. - it('should not affected queries for projected templates if views are detached or moved', () => { - const template = - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q'] as ManualProjecting; - expect(q.query.length).toBe(0); + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should not affected queries for projected templates if views are detached or moved', () => { + const template = + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); + const q = view.debugElement.children[0].references !['q'] as ManualProjecting; + expect(q.query.length).toBe(0); - const view1 = q.vc.createEmbeddedView(q.template, {'x': '1'}); - const view2 = q.vc.createEmbeddedView(q.template, {'x': '2'}); - view.detectChanges(); - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']); + const view1 = q.vc.createEmbeddedView(q.template, {'x': '1'}); + const view2 = q.vc.createEmbeddedView(q.template, {'x': '2'}); + view.detectChanges(); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']); - q.vc.detach(1); - q.vc.detach(0); + q.vc.detach(1); + q.vc.detach(0); - view.detectChanges(); - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']); + view.detectChanges(); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']); - q.vc.insert(view2); - q.vc.insert(view1); + q.vc.insert(view2); + q.vc.insert(view1); - view.detectChanges(); - expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']); - }); + view.detectChanges(); + expect(q.query.map((d: TextDirective) => d.text)).toEqual(['1', '2']); + }); - it('should remove manually projected templates if their parent view is destroyed', () => { - const template = ` + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should remove manually projected templates if their parent view is destroyed', () => { + const template = `
`; - const view = createTestCmp(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; - view.componentInstance.shouldShow = true; - view.detectChanges(); + const view = createTestCmp(MyComp0, template); + const q = view.debugElement.children[0].references !['q']; + view.componentInstance.shouldShow = true; + view.detectChanges(); - expect(q.query.length).toBe(1); + expect(q.query.length).toBe(1); - view.componentInstance.shouldShow = false; - view.detectChanges(); - expect(q.query.length).toBe(0); - }); + view.componentInstance.shouldShow = false; + view.detectChanges(); + expect(q.query.length).toBe(0); + }); - it('should not throw if a content template is queried and created in the view during change detection', - () => { - @Component( - {selector: 'auto-projecting', template: '
'}) - class AutoProjecting { - // TODO(issue/24571): - // remove - // '!'. - @ContentChild(TemplateRef) - content !: TemplateRef; + fixmeIvy('FW-670: Internal Error: The name q is already defined in scope') && + it('should not throw if a content template is queried and created in the view during change detection', + () => { + @Component( + {selector: 'auto-projecting', template: '
'}) + class AutoProjecting { + // TODO(issue/24571): + // remove + // '!'. + @ContentChild(TemplateRef) + content !: TemplateRef; - // TODO(issue/24571): - // remove - // '!'. - @ContentChildren(TextDirective) - query !: QueryList; - } + // TODO(issue/24571): + // remove + // '!'. + @ContentChildren(TextDirective) + query !: QueryList; + } - TestBed.configureTestingModule({declarations: [AutoProjecting]}); - const template = - '
'; - const view = createTestCmpAndDetectChanges(MyComp0, template); + TestBed.configureTestingModule({declarations: [AutoProjecting]}); + const template = + '
'; + const view = createTestCmpAndDetectChanges(MyComp0, template); - const q = view.debugElement.children[0].references !['q']; - // This - // should - // be - // 1, - // but - // due - // to - // https://github.com/angular/angular/issues/15117 - // this - // is - // 0. - expect(q.query.length).toBe(0); - }); + const q = view.debugElement.children[0].references !['q']; + // This + // should + // be + // 1, + // but + // due + // to + // https://github.com/angular/angular/issues/15117 + // this + // is + // 0. + expect(q.query.length).toBe(0); + }); }); }); diff --git a/packages/core/test/linker/security_integration_spec.ts b/packages/core/test/linker/security_integration_spec.ts index 0f179283f9..013d539812 100644 --- a/packages/core/test/linker/security_integration_spec.ts +++ b/packages/core/test/linker/security_integration_spec.ts @@ -14,7 +14,7 @@ import {fixmeIvy} from '@angular/private/testing'; { if (ivyEnabled) { - fixmeIvy('unknown') && describe('ivy', () => { declareTests(); }); + describe('ivy', () => { declareTests(); }); } else { describe('jit', () => { declareTests({useJit: true}); }); describe('no jit', () => { declareTests({useJit: false}); }); @@ -52,7 +52,7 @@ function declareTests(config?: {useJit: boolean}) { afterEach(() => { getDOM().log = originalLog; }); describe('events', () => { - it('should disallow binding to attr.on*', () => { + fixmeIvy('unknown') && it('should disallow binding to attr.on*', () => { const template = `
`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); @@ -61,7 +61,7 @@ function declareTests(config?: {useJit: boolean}) { /Binding to event attribute 'onclick' is disallowed for security reasons, please use \(click\)=.../); }); - it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => { + fixmeIvy('unknown') && it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => { const template = `
`; TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({ schemas: [NO_ERRORS_SCHEMA] @@ -72,29 +72,30 @@ function declareTests(config?: {useJit: boolean}) { /Binding to event property 'onclick' is disallowed for security reasons, please use \(click\)=.../); }); - it('should disallow binding to on* unless it is consumed by a directive', () => { - const template = `
`; - TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({ - schemas: [NO_ERRORS_SCHEMA] - }); + fixmeIvy('unknown') && + it('should disallow binding to on* unless it is consumed by a directive', () => { + const template = `
`; + TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({ + schemas: [NO_ERRORS_SCHEMA] + }); - // should not throw for inputs starting with "on" - let cmp: ComponentFixture = undefined !; - expect(() => cmp = TestBed.createComponent(SecuredComponent)).not.toThrow(); + // should not throw for inputs starting with "on" + let cmp: ComponentFixture = undefined !; + expect(() => cmp = TestBed.createComponent(SecuredComponent)).not.toThrow(); - // must bind to the directive not to the property of the div - const value = cmp.componentInstance.ctxProp = {}; - cmp.detectChanges(); - const div = cmp.debugElement.children[0]; - expect(div.injector.get(OnPrefixDir).onclick).toBe(value); - expect(getDOM().getProperty(div.nativeElement, 'onclick')).not.toBe(value); - expect(getDOM().hasAttribute(div.nativeElement, 'onclick')).toEqual(false); - }); + // must bind to the directive not to the property of the div + const value = cmp.componentInstance.ctxProp = {}; + cmp.detectChanges(); + const div = cmp.debugElement.children[0]; + expect(div.injector.get(OnPrefixDir).onclick).toBe(value); + expect(getDOM().getProperty(div.nativeElement, 'onclick')).not.toBe(value); + expect(getDOM().hasAttribute(div.nativeElement, 'onclick')).toEqual(false); + }); }); describe('safe HTML values', function() { - it('should not escape values marked as trusted', () => { + fixmeIvy('unknown') && it('should not escape values marked as trusted', () => { const template = `Link Title`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); const fixture = TestBed.createComponent(SecuredComponent); @@ -108,7 +109,7 @@ function declareTests(config?: {useJit: boolean}) { expect(getDOM().getProperty(e, 'href')).toEqual('javascript:alert(1)'); }); - it('should error when using the wrong trusted value', () => { + fixmeIvy('unknown') && it('should error when using the wrong trusted value', () => { const template = `Link Title`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); const fixture = TestBed.createComponent(SecuredComponent); @@ -120,7 +121,7 @@ function declareTests(config?: {useJit: boolean}) { expect(() => fixture.detectChanges()).toThrowError(/Required a safe URL, got a Script/); }); - it('should warn when using in string interpolation', () => { + fixmeIvy('unknown') && it('should warn when using in string interpolation', () => { const template = `Link Title`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); const fixture = TestBed.createComponent(SecuredComponent); @@ -153,7 +154,7 @@ function declareTests(config?: {useJit: boolean}) { expect(value).toEqual('unsafe:javascript:alert(1)'); } - it('should escape unsafe properties', () => { + fixmeIvy('unknown') && it('should escape unsafe properties', () => { const template = `Link Title`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); const fixture = TestBed.createComponent(SecuredComponent); @@ -161,7 +162,7 @@ function declareTests(config?: {useJit: boolean}) { checkEscapeOfHrefProperty(fixture, false); }); - it('should escape unsafe attributes', () => { + fixmeIvy('unknown') && it('should escape unsafe attributes', () => { const template = `Link Title`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); const fixture = TestBed.createComponent(SecuredComponent); @@ -169,39 +170,41 @@ function declareTests(config?: {useJit: boolean}) { checkEscapeOfHrefProperty(fixture, true); }); - it('should escape unsafe properties if they are used in host bindings', () => { - @Directive({selector: '[dirHref]'}) - class HrefDirective { - // TODO(issue/24571): remove '!'. - @HostBinding('href') @Input() - dirHref !: string; - } + fixmeIvy('unknown') && + it('should escape unsafe properties if they are used in host bindings', () => { + @Directive({selector: '[dirHref]'}) + class HrefDirective { + // TODO(issue/24571): remove '!'. + @HostBinding('href') @Input() + dirHref !: string; + } - const template = `Link Title`; - TestBed.configureTestingModule({declarations: [HrefDirective]}); - TestBed.overrideComponent(SecuredComponent, {set: {template}}); - const fixture = TestBed.createComponent(SecuredComponent); + const template = `Link Title`; + TestBed.configureTestingModule({declarations: [HrefDirective]}); + TestBed.overrideComponent(SecuredComponent, {set: {template}}); + const fixture = TestBed.createComponent(SecuredComponent); - checkEscapeOfHrefProperty(fixture, false); - }); + checkEscapeOfHrefProperty(fixture, false); + }); - it('should escape unsafe attributes if they are used in host bindings', () => { - @Directive({selector: '[dirHref]'}) - class HrefDirective { - // TODO(issue/24571): remove '!'. - @HostBinding('attr.href') @Input() - dirHref !: string; - } + fixmeIvy('unknown') && + it('should escape unsafe attributes if they are used in host bindings', () => { + @Directive({selector: '[dirHref]'}) + class HrefDirective { + // TODO(issue/24571): remove '!'. + @HostBinding('attr.href') @Input() + dirHref !: string; + } - const template = `Link Title`; - TestBed.configureTestingModule({declarations: [HrefDirective]}); - TestBed.overrideComponent(SecuredComponent, {set: {template}}); - const fixture = TestBed.createComponent(SecuredComponent); + const template = `Link Title`; + TestBed.configureTestingModule({declarations: [HrefDirective]}); + TestBed.overrideComponent(SecuredComponent, {set: {template}}); + const fixture = TestBed.createComponent(SecuredComponent); - checkEscapeOfHrefProperty(fixture, true); - }); + checkEscapeOfHrefProperty(fixture, true); + }); - it('should escape unsafe style values', () => { + fixmeIvy('unknown') && it('should escape unsafe style values', () => { const template = `
Text
`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); const fixture = TestBed.createComponent(SecuredComponent); @@ -221,7 +224,7 @@ function declareTests(config?: {useJit: boolean}) { expect(getDOM().getStyle(e, 'background')).not.toContain('javascript'); }); - it('should escape unsafe SVG attributes', () => { + fixmeIvy('unknown') && it('should escape unsafe SVG attributes', () => { const template = `Text`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); @@ -229,7 +232,7 @@ function declareTests(config?: {useJit: boolean}) { .toThrowError(/Can't bind to 'xlink:href'/); }); - it('should escape unsafe HTML values', () => { + fixmeIvy('unknown') && it('should escape unsafe HTML values', () => { const template = `
Text
`; TestBed.overrideComponent(SecuredComponent, {set: {template}}); const fixture = TestBed.createComponent(SecuredComponent); diff --git a/packages/core/test/linker/source_map_integration_node_only_spec.ts b/packages/core/test/linker/source_map_integration_node_only_spec.ts index 42e5db75df..6192a08fb7 100644 --- a/packages/core/test/linker/source_map_integration_node_only_spec.ts +++ b/packages/core/test/linker/source_map_integration_node_only_spec.ts @@ -16,7 +16,7 @@ import {TestBed, fakeAsync, tick} from '@angular/core/testing'; import {fixmeIvy} from '@angular/private/testing'; { - fixmeIvy('unknown') && describe('jit source mapping', () => { + describe('jit source mapping', () => { let jitSpy: jasmine.Spy; let resourceLoader: MockResourceLoader; @@ -102,160 +102,167 @@ import {fixmeIvy} from '@angular/private/testing'; function declareTests( {ngUrl, templateDecorator}: {ngUrl: string, templateDecorator: (template: string) => { [key: string]: any }}) { - it('should use the right source url in html parse errors', fakeAsync(() => { - @Component({...templateDecorator('
\n ')}) - class MyComp { - } - - expect(() => compileAndCreateComponent(MyComp)) - .toThrowError( - new RegExp(`Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:2`)); - })); - - it('should use the right source url in template parse errors', fakeAsync(() => { - @Component({...templateDecorator('
\n
')}) - class MyComp { - } - - expect(() => compileAndCreateComponent(MyComp)) - .toThrowError( - new RegExp(`Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:7`)); - })); - - it('should create a sourceMap for templates', fakeAsync(() => { - const template = `Hello World!`; - - @Component({...templateDecorator(template)}) - class MyComp { - } - - compileAndCreateComponent(MyComp); - - const sourceMap = getSourceMap('ng:///DynamicTestModule/MyComp.ngfactory.js'); - expect(sourceMap.sources).toEqual([ - 'ng:///DynamicTestModule/MyComp.ngfactory.js', ngUrl - ]); - expect(sourceMap.sourcesContent).toEqual([' ', template]); - })); - - - it('should report source location for di errors', fakeAsync(() => { - const template = `
\n
`; - - @Component({...templateDecorator(template)}) - class MyComp { - } - - @Directive({selector: '[someDir]'}) - class SomeDir { - constructor() { throw new Error('Test'); } - } - - TestBed.configureTestingModule({declarations: [SomeDir]}); - let error: any; - try { - compileAndCreateComponent(MyComp); - } catch (e) { - error = e; - } - // The error should be logged from the element - expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ - line: 2, - column: 4, - source: ngUrl, - }); - })); - - it('should report di errors with multiple elements and directives', fakeAsync(() => { - const template = `
`; - - @Component({...templateDecorator(template)}) - class MyComp { - } - - @Directive({selector: '[someDir]'}) - class SomeDir { - constructor(@Attribute('someDir') someDir: string) { - if (someDir === 'throw') { - throw new Error('Test'); + fixmeIvy('unknown') && + it('should use the right source url in html parse errors', fakeAsync(() => { + @Component({...templateDecorator('
\n ')}) + class MyComp { } - } - } - TestBed.configureTestingModule({declarations: [SomeDir]}); - let error: any; - try { - compileAndCreateComponent(MyComp); - } catch (e) { - error = e; - } - // The error should be logged from the 2nd-element - expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ - line: 1, - column: 19, - source: ngUrl, - }); - })); + expect(() => compileAndCreateComponent(MyComp)) + .toThrowError(new RegExp( + `Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:2`)); + })); - it('should report source location for binding errors', fakeAsync(() => { - const template = `
\n
`; + fixmeIvy('unknown') && + it('should use the right source url in template parse errors', fakeAsync(() => { + @Component({...templateDecorator('
\n
')}) + class MyComp { + } - @Component({...templateDecorator(template)}) - class MyComp { - createError() { throw new Error('Test'); } - } + expect(() => compileAndCreateComponent(MyComp)) + .toThrowError(new RegExp( + `Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:7`)); + })); - const comp = compileAndCreateComponent(MyComp); + fixmeIvy('unknown') && it('should create a sourceMap for templates', fakeAsync(() => { + const template = `Hello World!`; - let error: any; - try { - comp.detectChanges(); - } catch (e) { - error = e; - } - // the stack should point to the binding - expect(getSourcePositionForStack(error.stack)).toEqual({ - line: 2, - column: 12, - source: ngUrl, - }); - // The error should be logged from the element - expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ - line: 2, - column: 4, - source: ngUrl, - }); - })); + @Component({...templateDecorator(template)}) + class MyComp { + } - it('should report source location for event errors', fakeAsync(() => { - const template = `
\n
`; + compileAndCreateComponent(MyComp); - @Component({...templateDecorator(template)}) - class MyComp { - createError() { throw new Error('Test'); } - } + const sourceMap = + getSourceMap('ng:///DynamicTestModule/MyComp.ngfactory.js'); + expect(sourceMap.sources).toEqual([ + 'ng:///DynamicTestModule/MyComp.ngfactory.js', ngUrl + ]); + expect(sourceMap.sourcesContent).toEqual([' ', template]); + })); - const comp = compileAndCreateComponent(MyComp); - let error: any; - const errorHandler = TestBed.get(ErrorHandler); - spyOn(errorHandler, 'handleError').and.callFake((e: any) => error = e); - comp.debugElement.children[0].children[0].triggerEventHandler('click', 'EVENT'); - expect(error).toBeTruthy(); - // the stack should point to the binding - expect(getSourcePositionForStack(error.stack)).toEqual({ - line: 2, - column: 12, - source: ngUrl, - }); - // The error should be logged from the element - expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ - line: 2, - column: 4, - source: ngUrl, - }); + fixmeIvy('unknown') && + it('should report source location for di errors', fakeAsync(() => { + const template = `
\n
`; - })); + @Component({...templateDecorator(template)}) + class MyComp { + } + + @Directive({selector: '[someDir]'}) + class SomeDir { + constructor() { throw new Error('Test'); } + } + + TestBed.configureTestingModule({declarations: [SomeDir]}); + let error: any; + try { + compileAndCreateComponent(MyComp); + } catch (e) { + error = e; + } + // The error should be logged from the element + expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ + line: 2, + column: 4, + source: ngUrl, + }); + })); + + fixmeIvy('unknown') && + it('should report di errors with multiple elements and directives', fakeAsync(() => { + const template = `
`; + + @Component({...templateDecorator(template)}) + class MyComp { + } + + @Directive({selector: '[someDir]'}) + class SomeDir { + constructor(@Attribute('someDir') someDir: string) { + if (someDir === 'throw') { + throw new Error('Test'); + } + } + } + + TestBed.configureTestingModule({declarations: [SomeDir]}); + let error: any; + try { + compileAndCreateComponent(MyComp); + } catch (e) { + error = e; + } + // The error should be logged from the 2nd-element + expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ + line: 1, + column: 19, + source: ngUrl, + }); + })); + + fixmeIvy('unknown') && + it('should report source location for binding errors', fakeAsync(() => { + const template = `
\n
`; + + @Component({...templateDecorator(template)}) + class MyComp { + createError() { throw new Error('Test'); } + } + + const comp = compileAndCreateComponent(MyComp); + + let error: any; + try { + comp.detectChanges(); + } catch (e) { + error = e; + } + // the stack should point to the binding + expect(getSourcePositionForStack(error.stack)).toEqual({ + line: 2, + column: 12, + source: ngUrl, + }); + // The error should be logged from the element + expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ + line: 2, + column: 4, + source: ngUrl, + }); + })); + + fixmeIvy('unknown') && + it('should report source location for event errors', fakeAsync(() => { + const template = `
\n
`; + + @Component({...templateDecorator(template)}) + class MyComp { + createError() { throw new Error('Test'); } + } + + const comp = compileAndCreateComponent(MyComp); + + let error: any; + const errorHandler = TestBed.get(ErrorHandler); + spyOn(errorHandler, 'handleError').and.callFake((e: any) => error = e); + comp.debugElement.children[0].children[0].triggerEventHandler('click', 'EVENT'); + expect(error).toBeTruthy(); + // the stack should point to the binding + expect(getSourcePositionForStack(error.stack)).toEqual({ + line: 2, + column: 12, + source: ngUrl, + }); + // The error should be logged from the element + expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({ + line: 2, + column: 4, + source: ngUrl, + }); + + })); } }); } diff --git a/packages/core/test/render3/view_container_ref_spec.ts b/packages/core/test/render3/view_container_ref_spec.ts index b69bd2d24f..fa6e2de6f6 100644 --- a/packages/core/test/render3/view_container_ref_spec.ts +++ b/packages/core/test/render3/view_container_ref_spec.ts @@ -1564,7 +1564,7 @@ describe('ViewContainerRef', () => { }); }); - fixmeIvy(`Hooks don't run`) && describe('life cycle hooks', () => { + describe('life cycle hooks', () => { // Angular 5 reference: https://stackblitz.com/edit/lifecycle-hooks-vcref const log: string[] = []; @@ -1608,206 +1608,216 @@ describe('ViewContainerRef', () => { }); } - it('should call all hooks in correct order when creating with createEmbeddedView', () => { - function SomeComponent_Template_0(rf: RenderFlags, ctx: any) { - if (rf & RenderFlags.Create) { - element(0, 'hooks'); - } - if (rf & RenderFlags.Update) { - elementProperty(0, 'name', bind('C')); - } - } + fixmeIvy(`Hooks don't run`) && + it('should call all hooks in correct order when creating with createEmbeddedView', () => { + function SomeComponent_Template_0(rf: RenderFlags, ctx: any) { + if (rf & RenderFlags.Create) { + element(0, 'hooks'); + } + if (rf & RenderFlags.Update) { + elementProperty(0, 'name', bind('C')); + } + } - @Component({ - template: ` + @Component({ + template: ` ` - }) - class SomeComponent { - static ngComponentDef = defineComponent({ - type: SomeComponent, - selectors: [['some-comp']], - factory: () => new SomeComponent(), - consts: 4, - vars: 3, - template: (rf: RenderFlags, cmp: SomeComponent) => { - if (rf & RenderFlags.Create) { - template( - 0, SomeComponent_Template_0, 1, 1, null, [], ['foo', ''], templateRefExtractor); - element(2, 'hooks', ['vcref', '']); - element(3, 'hooks'); - } - if (rf & RenderFlags.Update) { - const tplRef = reference(1); - elementProperty(2, 'tplRef', bind(tplRef)); - elementProperty(2, 'name', bind('A')); - elementProperty(3, 'name', bind('B')); - } - }, - directives: [ComponentWithHooks, DirectiveWithVCRef] + }) + class SomeComponent { + static ngComponentDef = defineComponent({ + type: SomeComponent, + selectors: [['some-comp']], + factory: () => new SomeComponent(), + consts: 4, + vars: 3, + template: (rf: RenderFlags, cmp: SomeComponent) => { + if (rf & RenderFlags.Create) { + template( + 0, SomeComponent_Template_0, 1, 1, null, [], ['foo', ''], + templateRefExtractor); + element(2, 'hooks', ['vcref', '']); + element(3, 'hooks'); + } + if (rf & RenderFlags.Update) { + const tplRef = reference(1); + elementProperty(2, 'tplRef', bind(tplRef)); + elementProperty(2, 'name', bind('A')); + elementProperty(3, 'name', bind('B')); + } + }, + directives: [ComponentWithHooks, DirectiveWithVCRef] + }); + } + + log.length = 0; + + const fixture = new ComponentFixture(SomeComponent); + expect(log).toEqual([ + 'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B', + 'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B', + 'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B', + 'afterViewChecked-B' + ]); + + log.length = 0; + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', + 'afterViewChecked-A', 'afterViewChecked-B' + ]); + + log.length = 0; + directiveInstance !.vcref.createEmbeddedView( + directiveInstance !.tplRef, fixture.component); + expect(fixture.html).toEqual('AB'); + expect(log).toEqual([]); + + log.length = 0; + fixture.update(); + expect(fixture.html).toEqual('ACB'); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'onChanges-C', 'onInit-C', 'doCheck-C', 'afterContentInit-C', + 'afterContentChecked-C', 'afterViewInit-C', 'afterViewChecked-C', + 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', + 'afterViewChecked-B' + ]); + + log.length = 0; + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C', + 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', + 'afterViewChecked-B' + ]); + + log.length = 0; + const viewRef = directiveInstance !.vcref.detach(0); + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', + 'afterViewChecked-A', 'afterViewChecked-B' + ]); + + log.length = 0; + directiveInstance !.vcref.insert(viewRef !); + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C', + 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', + 'afterViewChecked-B' + ]); + + log.length = 0; + directiveInstance !.vcref.remove(0); + fixture.update(); + expect(log).toEqual([ + 'onDestroy-C', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', + 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' + ]); }); - } - log.length = 0; - - const fixture = new ComponentFixture(SomeComponent); - expect(log).toEqual([ - 'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B', - 'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B', - 'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B', - 'afterViewChecked-B' - ]); - - log.length = 0; - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', - 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - directiveInstance !.vcref.createEmbeddedView(directiveInstance !.tplRef, fixture.component); - expect(fixture.html).toEqual('AB'); - expect(log).toEqual([]); - - log.length = 0; - fixture.update(); - expect(fixture.html).toEqual('ACB'); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'onChanges-C', 'onInit-C', 'doCheck-C', 'afterContentInit-C', - 'afterContentChecked-C', 'afterViewInit-C', 'afterViewChecked-C', 'afterContentChecked-A', - 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C', - 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - const viewRef = directiveInstance !.vcref.detach(0); - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', - 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - directiveInstance !.vcref.insert(viewRef !); - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C', - 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - directiveInstance !.vcref.remove(0); - fixture.update(); - expect(log).toEqual([ - 'onDestroy-C', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', - 'afterViewChecked-A', 'afterViewChecked-B' - ]); - }); - - it('should call all hooks in correct order when creating with createComponent', () => { - @Component({ - template: ` + fixmeIvy(`Hooks don't run`) && + it('should call all hooks in correct order when creating with createComponent', () => { + @Component({ + template: ` ` - }) - class SomeComponent { - static ngComponentDef = defineComponent({ - type: SomeComponent, - encapsulation: ViewEncapsulation.None, - selectors: [['some-comp']], - factory: () => new SomeComponent(), - consts: 2, - vars: 2, - template: (rf: RenderFlags, cmp: SomeComponent) => { - if (rf & RenderFlags.Create) { - element(0, 'hooks', ['vcref', '']); - element(1, 'hooks'); - } - if (rf & RenderFlags.Update) { - elementProperty(0, 'name', bind('A')); - elementProperty(1, 'name', bind('B')); - } - }, - directives: [ComponentWithHooks, DirectiveWithVCRef] + }) + class SomeComponent { + static ngComponentDef = defineComponent({ + type: SomeComponent, + encapsulation: ViewEncapsulation.None, + selectors: [['some-comp']], + factory: () => new SomeComponent(), + consts: 2, + vars: 2, + template: (rf: RenderFlags, cmp: SomeComponent) => { + if (rf & RenderFlags.Create) { + element(0, 'hooks', ['vcref', '']); + element(1, 'hooks'); + } + if (rf & RenderFlags.Update) { + elementProperty(0, 'name', bind('A')); + elementProperty(1, 'name', bind('B')); + } + }, + directives: [ComponentWithHooks, DirectiveWithVCRef] + }); + } + + log.length = 0; + + const fixture = new ComponentFixture(SomeComponent); + expect(log).toEqual([ + 'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B', + 'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B', + 'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B', + 'afterViewChecked-B' + ]); + + log.length = 0; + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', + 'afterViewChecked-A', 'afterViewChecked-B' + ]); + + log.length = 0; + const componentRef = directiveInstance !.vcref.createComponent( + directiveInstance !.cfr.resolveComponentFactory(ComponentWithHooks)); + expect(fixture.html).toEqual('AB'); + expect(log).toEqual([]); + + componentRef.instance.name = 'D'; + log.length = 0; + fixture.update(); + expect(fixture.html).toEqual('ADB'); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'onChanges-D', 'onInit-D', 'doCheck-D', 'afterContentInit-D', + 'afterContentChecked-D', 'afterViewInit-D', 'afterViewChecked-D', + 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', + 'afterViewChecked-B' + ]); + + log.length = 0; + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D', + 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', + 'afterViewChecked-B' + ]); + + log.length = 0; + const viewRef = directiveInstance !.vcref.detach(0); + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', + 'afterViewChecked-A', 'afterViewChecked-B' + ]); + + log.length = 0; + directiveInstance !.vcref.insert(viewRef !); + fixture.update(); + expect(log).toEqual([ + 'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D', + 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', + 'afterViewChecked-B' + ]); + + log.length = 0; + directiveInstance !.vcref.remove(0); + fixture.update(); + expect(log).toEqual([ + 'onDestroy-D', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', + 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' + ]); }); - } - - log.length = 0; - - const fixture = new ComponentFixture(SomeComponent); - expect(log).toEqual([ - 'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B', - 'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B', - 'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B', - 'afterViewChecked-B' - ]); - - log.length = 0; - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', - 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - const componentRef = directiveInstance !.vcref.createComponent( - directiveInstance !.cfr.resolveComponentFactory(ComponentWithHooks)); - expect(fixture.html).toEqual('AB'); - expect(log).toEqual([]); - - componentRef.instance.name = 'D'; - log.length = 0; - fixture.update(); - expect(fixture.html).toEqual('ADB'); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'onChanges-D', 'onInit-D', 'doCheck-D', 'afterContentInit-D', - 'afterContentChecked-D', 'afterViewInit-D', 'afterViewChecked-D', 'afterContentChecked-A', - 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D', - 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - const viewRef = directiveInstance !.vcref.detach(0); - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', - 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - directiveInstance !.vcref.insert(viewRef !); - fixture.update(); - expect(log).toEqual([ - 'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D', - 'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B' - ]); - - log.length = 0; - directiveInstance !.vcref.remove(0); - fixture.update(); - expect(log).toEqual([ - 'onDestroy-D', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B', - 'afterViewChecked-A', 'afterViewChecked-B' - ]); - }); }); describe('host bindings', () => { diff --git a/packages/core/test/view/provider_spec.ts b/packages/core/test/view/provider_spec.ts index 2c5ca9f8a5..78dac87989 100644 --- a/packages/core/test/view/provider_spec.ts +++ b/packages/core/test/view/provider_spec.ts @@ -114,10 +114,10 @@ import {fixmeIvy} from '@angular/private/testing'; expect(debugCtx.nodeIndex).toBe(1); }); - fixmeIvy('unknown') && describe('deps', () => { + describe('deps', () => { class Dep {} - it('should inject deps from the same element', () => { + fixmeIvy('unknown') && it('should inject deps from the same element', () => { createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 2, 'span'), directiveDef(1, NodeFlags.None, null, 0, Dep, []), @@ -127,7 +127,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep instanceof Dep).toBeTruthy(); }); - it('should inject deps from a parent element', () => { + fixmeIvy('unknown') && it('should inject deps from a parent element', () => { createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 3, 'span'), directiveDef(1, NodeFlags.None, null, 0, Dep, []), @@ -138,7 +138,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep instanceof Dep).toBeTruthy(); }); - it('should not inject deps from sibling root elements', () => { + fixmeIvy('unknown') && it('should not inject deps from sibling root elements', () => { const rootElNodes = [ elementDef(0, NodeFlags.None, null, null, 1, 'span'), directiveDef(1, NodeFlags.None, null, 0, Dep, []), @@ -167,7 +167,7 @@ import {fixmeIvy} from '@angular/private/testing'; ' NullInjectorError: No provider for Dep!'); }); - it('should inject from a parent element in a parent view', () => { + fixmeIvy('unknown') && it('should inject from a parent element in a parent view', () => { createAndGetRootNodes(compViewDef([ elementDef( 0, NodeFlags.None, null, null, 1, 'div', null, null, null, null, @@ -181,7 +181,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep instanceof Dep).toBeTruthy(); }); - it('should throw for missing dependencies', () => { + fixmeIvy('unknown') && it('should throw for missing dependencies', () => { expect(() => createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 1, 'span'), directiveDef(1, NodeFlags.None, null, 0, SomeService, ['nonExistingDep']) @@ -192,7 +192,7 @@ import {fixmeIvy} from '@angular/private/testing'; ' NullInjectorError: No provider for nonExistingDep!'); }); - it('should use null for optional missing dependencies', () => { + fixmeIvy('unknown') && it('should use null for optional missing dependencies', () => { createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 1, 'span'), directiveDef( @@ -202,7 +202,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep).toBe(null); }); - it('should skip the current element when using SkipSelf', () => { + fixmeIvy('unknown') && it('should skip the current element when using SkipSelf', () => { createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 4, 'span'), providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someParentValue', []), @@ -214,18 +214,19 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep).toBe('someParentValue'); }); - it('should ask the root injector', - withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => { - createAndGetRootNodes(compViewDef([ - elementDef(0, NodeFlags.None, null, null, 1, 'span'), - directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep']) - ])); + fixmeIvy('unknown') && + it('should ask the root injector', + withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => { + createAndGetRootNodes(compViewDef([ + elementDef(0, NodeFlags.None, null, null, 1, 'span'), + directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep']) + ])); - expect(instance.dep).toBe('rootValue'); - })); + expect(instance.dep).toBe('rootValue'); + })); describe('builtin tokens', () => { - it('should inject ViewContainerRef', () => { + fixmeIvy('unknown') && it('should inject ViewContainerRef', () => { createAndGetRootNodes(compViewDef([ anchorDef(NodeFlags.EmbeddedViews, null, null, 1), directiveDef(1, NodeFlags.None, null, 0, SomeService, [ViewContainerRef]), @@ -234,7 +235,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep.createEmbeddedView).toBeTruthy(); }); - it('should inject TemplateRef', () => { + fixmeIvy('unknown') && it('should inject TemplateRef', () => { createAndGetRootNodes(compViewDef([ anchorDef(NodeFlags.None, null, null, 1, null, compViewDefFactory([anchorDef( NodeFlags.None, null, null, 0)])), @@ -244,7 +245,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep.createEmbeddedView).toBeTruthy(); }); - it('should inject ElementRef', () => { + fixmeIvy('unknown') && it('should inject ElementRef', () => { const {view} = createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 1, 'span'), directiveDef(1, NodeFlags.None, null, 0, SomeService, [ElementRef]), @@ -253,7 +254,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep.nativeElement).toBe(asElementData(view, 0).renderElement); }); - it('should inject Injector', () => { + fixmeIvy('unknown') && it('should inject Injector', () => { const {view} = createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 1, 'span'), directiveDef(1, NodeFlags.None, null, 0, SomeService, [Injector]), @@ -262,30 +263,32 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep.get(SomeService)).toBe(instance); }); - it('should inject ChangeDetectorRef for non component providers', () => { - const {view} = createAndGetRootNodes(compViewDef([ - elementDef(0, NodeFlags.None, null, null, 1, 'span'), - directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef]) - ])); + fixmeIvy('unknown') && + it('should inject ChangeDetectorRef for non component providers', () => { + const {view} = createAndGetRootNodes(compViewDef([ + elementDef(0, NodeFlags.None, null, null, 1, 'span'), + directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef]) + ])); - expect(instance.dep._view).toBe(view); - }); + expect(instance.dep._view).toBe(view); + }); - it('should inject ChangeDetectorRef for component providers', () => { - const {view, rootNodes} = createAndGetRootNodes(compViewDef([ - elementDef( - 0, NodeFlags.None, null, null, 1, 'div', null, null, null, null, - () => compViewDef([ - elementDef(0, NodeFlags.None, null, null, 0, 'span'), - ])), - directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]), - ])); + fixmeIvy('unknown') && + it('should inject ChangeDetectorRef for component providers', () => { + const {view, rootNodes} = createAndGetRootNodes(compViewDef([ + elementDef( + 0, NodeFlags.None, null, null, 1, 'div', null, null, null, null, + () => compViewDef([ + elementDef(0, NodeFlags.None, null, null, 0, 'span'), + ])), + directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]), + ])); - const compView = asElementData(view, 0).componentView; - expect(instance.dep._view).toBe(compView); - }); + const compView = asElementData(view, 0).componentView; + expect(instance.dep._view).toBe(compView); + }); - it('should inject RendererV1', () => { + fixmeIvy('unknown') && it('should inject RendererV1', () => { createAndGetRootNodes(compViewDef([ elementDef( 0, NodeFlags.None, null, null, 1, 'span', null, null, null, null, @@ -296,7 +299,7 @@ import {fixmeIvy} from '@angular/private/testing'; expect(instance.dep.createElement).toBeTruthy(); }); - it('should inject Renderer2', () => { + fixmeIvy('unknown') && it('should inject Renderer2', () => { createAndGetRootNodes(compViewDef([ elementDef( 0, NodeFlags.None, null, null, 1, 'span', null, null, null, null,