diff --git a/packages/common/test/BUILD.bazel b/packages/common/test/BUILD.bazel index d550182039..3a7c7cf38f 100644 --- a/packages/common/test/BUILD.bazel +++ b/packages/common/test/BUILD.bazel @@ -15,15 +15,13 @@ ts_library( "//packages/platform-browser", "//packages/platform-browser-dynamic", "//packages/platform-browser/testing", + "//packages/private/testing", ], ) jasmine_node_test( name = "test", bootstrap = ["angular/tools/testing/init_node_spec.js"], - tags = [ - "fixme-ivy-aot", - ], deps = [ ":test_lib", "//tools/testing:node", @@ -32,9 +30,6 @@ jasmine_node_test( ts_web_test_suite( name = "test_web", - tags = [ - "fixme-ivy-aot", - ], deps = [ ":test_lib", ], diff --git a/packages/common/test/common_module_spec.ts b/packages/common/test/common_module_spec.ts index be40f6722f..773df8a328 100644 --- a/packages/common/test/common_module_spec.ts +++ b/packages/common/test/common_module_spec.ts @@ -7,20 +7,17 @@ */ +import {DeprecatedI18NPipesModule, Plural} from '@angular/common'; +import {DEPRECATED_PLURAL_FN, getPluralCase} from '@angular/common/src/i18n/localization'; import {TestBed, inject} from '@angular/core/testing'; -import {DeprecatedI18NPipesModule} from '../src/common_module'; -import {Plural} from '../src/i18n/locale_data_api'; -import {DEPRECATED_PLURAL_FN, getPluralCase} from '../src/i18n/localization'; -{ - describe('DeprecatedI18NPipesModule', () => { - beforeEach(() => { TestBed.configureTestingModule({imports: [DeprecatedI18NPipesModule]}); }); +describe('DeprecatedI18NPipesModule', () => { + beforeEach(() => { TestBed.configureTestingModule({imports: [DeprecatedI18NPipesModule]}); }); - it('should define the token DEPRECATED_PLURAL_FN', - inject( - [DEPRECATED_PLURAL_FN], - (injectedGetPluralCase?: (locale: string, value: number | string) => Plural) => { - expect(injectedGetPluralCase).toEqual(getPluralCase); - })); - }); -} + it('should define the token DEPRECATED_PLURAL_FN', + inject( + [DEPRECATED_PLURAL_FN], + (injectedGetPluralCase?: (locale: string, value: number | string) => Plural) => { + expect(injectedGetPluralCase).toEqual(getPluralCase); + })); +}); diff --git a/packages/common/test/directives/ng_component_outlet_spec.ts b/packages/common/test/directives/ng_component_outlet_spec.ts index 39f0b3d317..4b59d8b4d1 100644 --- a/packages/common/test/directives/ng_component_outlet_spec.ts +++ b/packages/common/test/directives/ng_component_outlet_spec.ts @@ -8,206 +8,211 @@ import {CommonModule} from '@angular/common'; import {NgComponentOutlet} from '@angular/common/src/directives/ng_component_outlet'; -import {Compiler, Component, ComponentRef, Inject, InjectionToken, Injector, NO_ERRORS_SCHEMA, NgModule, NgModuleFactory, Optional, QueryList, StaticProvider, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core'; -import {TestBed, async, fakeAsync} from '@angular/core/testing'; +import {Compiler, Component, ComponentRef, Inject, InjectionToken, Injector, NO_ERRORS_SCHEMA, NgModule, NgModuleFactory, Optional, QueryList, TemplateRef, Type, ViewChild, ViewChildren, ViewContainerRef} from '@angular/core'; +import {TestBed, async} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/src/matchers'; +import {fixmeIvy} from '@angular/private/testing'; -{ - describe('insert/remove', () => { +describe('insert/remove', () => { - beforeEach(() => { TestBed.configureTestingModule({imports: [TestModule]}); }); + beforeEach(() => { TestBed.configureTestingModule({imports: [TestModule]}); }); - it('should do nothing if component is null', async(() => { - const template = ``; - TestBed.overrideComponent(TestComponent, {set: {template: template}}); - let fixture = TestBed.createComponent(TestComponent); + it('should do nothing if component is null', async(() => { + const template = ``; + TestBed.overrideComponent(TestComponent, {set: {template: template}}); + let fixture = TestBed.createComponent(TestComponent); - fixture.componentInstance.currentComponent = null; - fixture.detectChanges(); + fixture.componentInstance.currentComponent = null; + fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); - })); + expect(fixture.nativeElement).toHaveText(''); + })); - it('should insert content specified by a component', async(() => { - let fixture = TestBed.createComponent(TestComponent); + it('should insert content specified by a component', async(() => { + let fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText(''); - fixture.componentInstance.currentComponent = InjectedComponent; + fixture.componentInstance.currentComponent = InjectedComponent; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('foo'); - })); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('foo'); + })); - it('should emit a ComponentRef once a component was created', async(() => { - let fixture = TestBed.createComponent(TestComponent); + it('should emit a ComponentRef once a component was created', async(() => { + let fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText(''); - fixture.componentInstance.cmpRef = null; - fixture.componentInstance.currentComponent = InjectedComponent; + fixture.componentInstance.cmpRef = null; + fixture.componentInstance.currentComponent = InjectedComponent; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('foo'); - expect(fixture.componentInstance.cmpRef).toBeAnInstanceOf(ComponentRef); - expect(fixture.componentInstance.cmpRef !.instance).toBeAnInstanceOf(InjectedComponent); - })); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('foo'); + expect(fixture.componentInstance.cmpRef).toBeAnInstanceOf(ComponentRef); + expect(fixture.componentInstance.cmpRef !.instance).toBeAnInstanceOf(InjectedComponent); + })); - it('should clear view if component becomes null', async(() => { - let fixture = TestBed.createComponent(TestComponent); + it('should clear view if component becomes null', async(() => { + let fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText(''); - fixture.componentInstance.currentComponent = InjectedComponent; + fixture.componentInstance.currentComponent = InjectedComponent; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('foo'); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('foo'); - fixture.componentInstance.currentComponent = null; + fixture.componentInstance.currentComponent = null; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); - })); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText(''); + })); - it('should swap content if component changes', async(() => { - let fixture = TestBed.createComponent(TestComponent); + it('should swap content if component changes', async(() => { + let fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText(''); - fixture.componentInstance.currentComponent = InjectedComponent; + fixture.componentInstance.currentComponent = InjectedComponent; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('foo'); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('foo'); - fixture.componentInstance.currentComponent = InjectedComponentAgain; + fixture.componentInstance.currentComponent = InjectedComponentAgain; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('bar'); - })); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('bar'); + })); - it('should use the injector, if one supplied', async(() => { - let fixture = TestBed.createComponent(TestComponent); + fixmeIvy('ComponentFactoryResolver not resolved with supplied injector') && + it('should use the injector, if one supplied', async(() => { + let fixture = TestBed.createComponent(TestComponent); - const uniqueValue = {}; - fixture.componentInstance.currentComponent = InjectedComponent; - fixture.componentInstance.injector = Injector.create( - [{provide: TEST_TOKEN, useValue: uniqueValue}], fixture.componentRef.injector); + const uniqueValue = {}; + fixture.componentInstance.currentComponent = InjectedComponent; + fixture.componentInstance.injector = Injector.create( + [{provide: TEST_TOKEN, useValue: uniqueValue}], fixture.componentRef.injector); - fixture.detectChanges(); - let cmpRef: ComponentRef = fixture.componentInstance.cmpRef !; - expect(cmpRef).toBeAnInstanceOf(ComponentRef); - expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent); - expect(cmpRef.instance.testToken).toBe(uniqueValue); + fixture.detectChanges(); + let cmpRef: ComponentRef = fixture.componentInstance.cmpRef !; + expect(cmpRef).toBeAnInstanceOf(ComponentRef); + expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent); + expect(cmpRef.instance.testToken).toBe(uniqueValue); - })); + })); - it('should resolve a with injector', async(() => { - let fixture = TestBed.createComponent(TestComponent); + it('should resolve a with injector', async(() => { + let fixture = TestBed.createComponent(TestComponent); - fixture.componentInstance.cmpRef = null; - fixture.componentInstance.currentComponent = InjectedComponent; - fixture.detectChanges(); - let cmpRef: ComponentRef = fixture.componentInstance.cmpRef !; - expect(cmpRef).toBeAnInstanceOf(ComponentRef); - expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent); - expect(cmpRef.instance.testToken).toBeNull(); - })); + fixture.componentInstance.cmpRef = null; + fixture.componentInstance.currentComponent = InjectedComponent; + fixture.detectChanges(); + let cmpRef: ComponentRef = fixture.componentInstance.cmpRef !; + expect(cmpRef).toBeAnInstanceOf(ComponentRef); + expect(cmpRef.instance).toBeAnInstanceOf(InjectedComponent); + expect(cmpRef.instance.testToken).toBeNull(); + })); - it('should render projectable nodes, if supplied', async(() => { - const template = `projected foo${TEST_CMP_TEMPLATE}`; - TestBed.overrideComponent(TestComponent, {set: {template: template}}) - .configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}); + fixmeIvy('can not pass projectable nodes') && + it('should render projectable nodes, if supplied', async(() => { + const template = `projected foo${TEST_CMP_TEMPLATE}`; + TestBed.overrideComponent(TestComponent, {set: {template: template}}) + .configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}); - TestBed - .overrideComponent(InjectedComponent, {set: {template: ``}}) - .configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}); + TestBed + .overrideComponent(InjectedComponent, {set: {template: ``}}) + .configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}); - let fixture = TestBed.createComponent(TestComponent); + let fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText(''); - fixture.componentInstance.currentComponent = InjectedComponent; - fixture.componentInstance.projectables = - [fixture.componentInstance.vcRef - .createEmbeddedView(fixture.componentInstance.tplRefs.first) - .rootNodes]; + fixture.componentInstance.currentComponent = InjectedComponent; + fixture.componentInstance.projectables = + [fixture.componentInstance.vcRef + .createEmbeddedView(fixture.componentInstance.tplRefs.first) + .rootNodes]; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('projected foo'); - })); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('projected foo'); + })); - it('should resolve components from other modules, if supplied', async(() => { - const compiler = TestBed.get(Compiler) as Compiler; - let fixture = TestBed.createComponent(TestComponent); + fixmeIvy('Runtime compiler is not loaded') && + it('should resolve components from other modules, if supplied', async(() => { + const compiler = TestBed.get(Compiler) as Compiler; + let fixture = TestBed.createComponent(TestComponent); - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText(''); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText(''); - fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; + fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); + fixture.componentInstance.currentComponent = Module2InjectedComponent; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('baz'); - })); + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('baz'); + })); - it('should clean up moduleRef, if supplied', async(() => { - let destroyed = false; - const compiler = TestBed.get(Compiler) as Compiler; - const fixture = TestBed.createComponent(TestComponent); - fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; - fixture.detectChanges(); + fixmeIvy('Runtime compiler is not loaded') && + it('should clean up moduleRef, if supplied', async(() => { + let destroyed = false; + const compiler = TestBed.get(Compiler) as Compiler; + const fixture = TestBed.createComponent(TestComponent); + fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); + fixture.componentInstance.currentComponent = Module2InjectedComponent; + fixture.detectChanges(); - const moduleRef = fixture.componentInstance.ngComponentOutlet['_moduleRef'] !; - spyOn(moduleRef, 'destroy').and.callThrough(); + const moduleRef = fixture.componentInstance.ngComponentOutlet['_moduleRef'] !; + spyOn(moduleRef, 'destroy').and.callThrough(); - expect(moduleRef.destroy).not.toHaveBeenCalled(); - fixture.destroy(); - expect(moduleRef.destroy).toHaveBeenCalled(); - })); + expect(moduleRef.destroy).not.toHaveBeenCalled(); + fixture.destroy(); + expect(moduleRef.destroy).toHaveBeenCalled(); + })); - it('should not re-create moduleRef when it didn\'t actually change', async(() => { - const compiler = TestBed.get(Compiler) as Compiler; - const fixture = TestBed.createComponent(TestComponent); + fixmeIvy('Runtime compiler is not loaded') && + it('should not re-create moduleRef when it didn\'t actually change', async(() => { + const compiler = TestBed.get(Compiler) as Compiler; + const fixture = TestBed.createComponent(TestComponent); - fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; - fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('baz'); - const moduleRef = fixture.componentInstance.ngComponentOutlet['_moduleRef']; + fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); + fixture.componentInstance.currentComponent = Module2InjectedComponent; + fixture.detectChanges(); + expect(fixture.nativeElement).toHaveText('baz'); + const moduleRef = fixture.componentInstance.ngComponentOutlet['_moduleRef']; - fixture.componentInstance.currentComponent = Module2InjectedComponent2; - fixture.detectChanges(); + fixture.componentInstance.currentComponent = Module2InjectedComponent2; + fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('baz2'); - expect(moduleRef).toBe(fixture.componentInstance.ngComponentOutlet['_moduleRef']); - })); + expect(fixture.nativeElement).toHaveText('baz2'); + expect(moduleRef).toBe(fixture.componentInstance.ngComponentOutlet['_moduleRef']); + })); - it('should re-create moduleRef when changed', async(() => { - const compiler = TestBed.get(Compiler) as Compiler; - const fixture = TestBed.createComponent(TestComponent); - fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); - fixture.componentInstance.currentComponent = Module2InjectedComponent; - fixture.detectChanges(); + fixmeIvy('Runtime compiler is not loaded') && + it('should re-create moduleRef when changed', async(() => { + const compiler = TestBed.get(Compiler) as Compiler; + const fixture = TestBed.createComponent(TestComponent); + fixture.componentInstance.module = compiler.compileModuleSync(TestModule2); + fixture.componentInstance.currentComponent = Module2InjectedComponent; + fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('baz'); + expect(fixture.nativeElement).toHaveText('baz'); - fixture.componentInstance.module = compiler.compileModuleSync(TestModule3); - fixture.componentInstance.currentComponent = Module3InjectedComponent; - fixture.detectChanges(); + fixture.componentInstance.module = compiler.compileModuleSync(TestModule3); + fixture.componentInstance.currentComponent = Module3InjectedComponent; + fixture.detectChanges(); - expect(fixture.nativeElement).toHaveText('bat'); - })); - }); -} + expect(fixture.nativeElement).toHaveText('bat'); + })); +}); const TEST_TOKEN = new InjectionToken('TestToken'); @Component({selector: 'injected-component', template: 'foo'}) diff --git a/packages/common/test/directives/ng_template_outlet_spec.ts b/packages/common/test/directives/ng_template_outlet_spec.ts index 99dae02116..dc380a7808 100644 --- a/packages/common/test/directives/ng_template_outlet_spec.ts +++ b/packages/common/test/directives/ng_template_outlet_spec.ts @@ -10,205 +10,202 @@ import {CommonModule} from '@angular/common'; import {Component, ContentChildren, Directive, Injectable, NO_ERRORS_SCHEMA, OnDestroy, QueryList, TemplateRef} from '@angular/core'; import {ComponentFixture, TestBed, async} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/src/matchers'; +import {fixmeIvy} from '@angular/private/testing'; -{ - describe('NgTemplateOutlet', () => { - let fixture: ComponentFixture; +fixmeIvy('expr.visitExpression is not a function - fixed by #26968') && describe('NgTemplateOutlet', () => { + let fixture: ComponentFixture; - function setTplRef(value: any): void { fixture.componentInstance.currentTplRef = value; } + function setTplRef(value: any): void { fixture.componentInstance.currentTplRef = value; } - function detectChangesAndExpectText(text: string): void { - fixture.detectChanges(); - expect(fixture.debugElement.nativeElement).toHaveText(text); - } + function detectChangesAndExpectText(text: string): void { + fixture.detectChanges(); + expect(fixture.debugElement.nativeElement).toHaveText(text); + } - afterEach(() => { fixture = null as any; }); + afterEach(() => { fixture = null as any; }); - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [TestComponent, CaptureTplRefs, DestroyableCmpt], - imports: [CommonModule], - providers: [DestroyedSpyService] - }); - }); - - // https://github.com/angular/angular/issues/14778 - it('should accept the component as the context', async(() => { - const template = `` + - `{{context.foo}}`; - - fixture = createTestComponent(template); - detectChangesAndExpectText('bar'); - })); - - it('should do nothing if templateRef is `null`', async(() => { - const template = ``; - fixture = createTestComponent(template); - detectChangesAndExpectText(''); - })); - - it('should insert content specified by TemplateRef', async(() => { - const template = `foo` + - ``; - fixture = createTestComponent(template); - detectChangesAndExpectText('foo'); - })); - - it('should clear content if TemplateRef becomes `null`', async(() => { - const template = `foo` + - ``; - fixture = createTestComponent(template); - fixture.detectChanges(); - const refs = fixture.debugElement.children[0].references !['refs']; - - setTplRef(refs.tplRefs.first); - detectChangesAndExpectText('foo'); - - setTplRef(null); - detectChangesAndExpectText(''); - })); - - it('should swap content if TemplateRef changes', async(() => { - const template = - `foobar` + - ``; - fixture = createTestComponent(template); - - fixture.detectChanges(); - const refs = fixture.debugElement.children[0].references !['refs']; - - setTplRef(refs.tplRefs.first); - detectChangesAndExpectText('foo'); - - setTplRef(refs.tplRefs.last); - detectChangesAndExpectText('bar'); - })); - - it('should display template if context is `null`', async(() => { - const template = `foo` + - ``; - fixture = createTestComponent(template); - detectChangesAndExpectText('foo'); - })); - - it('should reflect initial context and changes', async(() => { - const template = `{{foo}}` + - ``; - fixture = createTestComponent(template); - - fixture.detectChanges(); - detectChangesAndExpectText('bar'); - - fixture.componentInstance.context.foo = 'alter-bar'; - detectChangesAndExpectText('alter-bar'); - })); - - it('should reflect user defined `$implicit` property in the context', async(() => { - const template = `{{ctx.foo}}` + - ``; - fixture = createTestComponent(template); - fixture.componentInstance.context = {$implicit: {foo: 'bra'}}; - detectChangesAndExpectText('bra'); - })); - - it('should reflect context re-binding', async(() => { - const template = - `{{shawshank}}` + - ``; - fixture = createTestComponent(template); - - fixture.componentInstance.context = {shawshank: 'brooks'}; - detectChangesAndExpectText('brooks'); - - fixture.componentInstance.context = {shawshank: 'was here'}; - detectChangesAndExpectText('was here'); - })); - - it('should update but not destroy embedded view when context values change', () => { - const template = - `:{{foo}}` + - ``; - - fixture = createTestComponent(template); - const spyService = fixture.debugElement.injector.get(DestroyedSpyService); - - detectChangesAndExpectText('Content to destroy:bar'); - expect(spyService.destroyed).toBeFalsy(); - - fixture.componentInstance.value = 'baz'; - detectChangesAndExpectText('Content to destroy:baz'); - expect(spyService.destroyed).toBeFalsy(); - }); - - it('should recreate embedded view when context shape changes', () => { - const template = - `:{{foo}}` + - ``; - - fixture = createTestComponent(template); - const spyService = fixture.debugElement.injector.get(DestroyedSpyService); - - detectChangesAndExpectText('Content to destroy:bar'); - expect(spyService.destroyed).toBeFalsy(); - - fixture.componentInstance.context = {foo: 'baz', other: true}; - detectChangesAndExpectText('Content to destroy:baz'); - expect(spyService.destroyed).toBeTruthy(); - }); - - it('should destroy embedded view when context value changes and templateRef becomes undefined', - () => { - const template = - `:{{foo}}` + - ``; - - fixture = createTestComponent(template); - const spyService = fixture.debugElement.injector.get(DestroyedSpyService); - - detectChangesAndExpectText('Content to destroy:bar'); - expect(spyService.destroyed).toBeFalsy(); - - fixture.componentInstance.value = 'baz'; - detectChangesAndExpectText(''); - expect(spyService.destroyed).toBeTruthy(); - }); - - it('should not try to update null / undefined context when context changes but template stays the same', - () => { - const template = `{{foo}}` + - ``; - - fixture = createTestComponent(template); - detectChangesAndExpectText(''); - - fixture.componentInstance.value = 'baz'; - detectChangesAndExpectText(''); - }); - - it('should not try to update null / undefined context when template changes', () => { - const template = `{{foo}}` + - `{{foo}}` + - ``; - - fixture = createTestComponent(template); - detectChangesAndExpectText(''); - - fixture.componentInstance.value = 'baz'; - detectChangesAndExpectText(''); - }); - - it('should not try to update context on undefined view', () => { - const template = `{{foo}}` + - ``; - - fixture = createTestComponent(template); - detectChangesAndExpectText(''); - - fixture.componentInstance.value = 'baz'; - detectChangesAndExpectText(''); + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [TestComponent, CaptureTplRefs, DestroyableCmpt], + imports: [CommonModule], + providers: [DestroyedSpyService] }); }); -} + + // https://github.com/angular/angular/issues/14778 + it('should accept the component as the context', async(() => { + const template = `` + + `{{context.foo}}`; + + fixture = createTestComponent(template); + detectChangesAndExpectText('bar'); + })); + + it('should do nothing if templateRef is `null`', async(() => { + const template = ``; + fixture = createTestComponent(template); + detectChangesAndExpectText(''); + })); + + it('should insert content specified by TemplateRef', async(() => { + const template = `foo` + + ``; + fixture = createTestComponent(template); + detectChangesAndExpectText('foo'); + })); + + it('should clear content if TemplateRef becomes `null`', async(() => { + const template = `foo` + + ``; + fixture = createTestComponent(template); + fixture.detectChanges(); + const refs = fixture.debugElement.children[0].references !['refs']; + + setTplRef(refs.tplRefs.first); + detectChangesAndExpectText('foo'); + + setTplRef(null); + detectChangesAndExpectText(''); + })); + + it('should swap content if TemplateRef changes', async(() => { + const template = + `foobar` + + ``; + fixture = createTestComponent(template); + + fixture.detectChanges(); + const refs = fixture.debugElement.children[0].references !['refs']; + + setTplRef(refs.tplRefs.first); + detectChangesAndExpectText('foo'); + + setTplRef(refs.tplRefs.last); + detectChangesAndExpectText('bar'); + })); + + it('should display template if context is `null`', async(() => { + const template = `foo` + + ``; + fixture = createTestComponent(template); + detectChangesAndExpectText('foo'); + })); + + it('should reflect initial context and changes', async(() => { + const template = `{{foo}}` + + ``; + fixture = createTestComponent(template); + + fixture.detectChanges(); + detectChangesAndExpectText('bar'); + + fixture.componentInstance.context.foo = 'alter-bar'; + detectChangesAndExpectText('alter-bar'); + })); + + it('should reflect user defined `$implicit` property in the context', async(() => { + const template = `{{ctx.foo}}` + + ``; + fixture = createTestComponent(template); + fixture.componentInstance.context = {$implicit: {foo: 'bra'}}; + detectChangesAndExpectText('bra'); + })); + + it('should reflect context re-binding', async(() => { + const template = `{{shawshank}}` + + ``; + fixture = createTestComponent(template); + + fixture.componentInstance.context = {shawshank: 'brooks'}; + detectChangesAndExpectText('brooks'); + + fixture.componentInstance.context = {shawshank: 'was here'}; + detectChangesAndExpectText('was here'); + })); + + it('should update but not destroy embedded view when context values change', () => { + const template = + `:{{foo}}` + + ``; + + fixture = createTestComponent(template); + const spyService = fixture.debugElement.injector.get(DestroyedSpyService); + + detectChangesAndExpectText('Content to destroy:bar'); + expect(spyService.destroyed).toBeFalsy(); + + fixture.componentInstance.value = 'baz'; + detectChangesAndExpectText('Content to destroy:baz'); + expect(spyService.destroyed).toBeFalsy(); + }); + + it('should recreate embedded view when context shape changes', () => { + const template = + `:{{foo}}` + + ``; + + fixture = createTestComponent(template); + const spyService = fixture.debugElement.injector.get(DestroyedSpyService); + + detectChangesAndExpectText('Content to destroy:bar'); + expect(spyService.destroyed).toBeFalsy(); + + fixture.componentInstance.context = {foo: 'baz', other: true}; + detectChangesAndExpectText('Content to destroy:baz'); + expect(spyService.destroyed).toBeTruthy(); + }); + + it('should destroy embedded view when context value changes and templateRef becomes undefined', () => { + const template = + `:{{foo}}` + + ``; + + fixture = createTestComponent(template); + const spyService = fixture.debugElement.injector.get(DestroyedSpyService); + + detectChangesAndExpectText('Content to destroy:bar'); + expect(spyService.destroyed).toBeFalsy(); + + fixture.componentInstance.value = 'baz'; + detectChangesAndExpectText(''); + expect(spyService.destroyed).toBeTruthy(); + }); + + it('should not try to update null / undefined context when context changes but template stays the same', + () => { + const template = `{{foo}}` + + ``; + + fixture = createTestComponent(template); + detectChangesAndExpectText(''); + + fixture.componentInstance.value = 'baz'; + detectChangesAndExpectText(''); + }); + + it('should not try to update null / undefined context when template changes', () => { + const template = `{{foo}}` + + `{{foo}}` + + ``; + + fixture = createTestComponent(template); + detectChangesAndExpectText(''); + + fixture.componentInstance.value = 'baz'; + detectChangesAndExpectText(''); + }); + + it('should not try to update context on undefined view', () => { + const template = `{{foo}}` + + ``; + + fixture = createTestComponent(template); + detectChangesAndExpectText(''); + + fixture.componentInstance.value = 'baz'; + detectChangesAndExpectText(''); + }); +}); @Injectable() class DestroyedSpyService { diff --git a/packages/common/test/i18n/localization_spec.ts b/packages/common/test/i18n/localization_spec.ts index 8eba92fb2c..d247d808d7 100644 --- a/packages/common/test/i18n/localization_spec.ts +++ b/packages/common/test/i18n/localization_spec.ts @@ -12,8 +12,8 @@ import localeZgh from '@angular/common/locales/zgh'; import localeFr from '@angular/common/locales/fr'; import {LOCALE_ID} from '@angular/core'; import {TestBed, inject} from '@angular/core/testing'; -import {NgLocaleLocalization, NgLocalization, getPluralCategory, DEPRECATED_PLURAL_FN, getPluralCase} from '../../src/i18n/localization'; -import {Plural} from '../../src/i18n/locale_data_api'; +import {NgLocaleLocalization, NgLocalization, getPluralCategory, DEPRECATED_PLURAL_FN, getPluralCase} from '@angular/common/src/i18n/localization'; +import {Plural} from '@angular/common'; import {registerLocaleData} from '../../src/i18n/locale_data'; { diff --git a/packages/common/test/location/location_spec.ts b/packages/common/test/location/location_spec.ts index 7d1fe22ebc..5f1a250a3e 100644 --- a/packages/common/test/location/location_spec.ts +++ b/packages/common/test/location/location_spec.ts @@ -6,37 +6,35 @@ * found in the LICENSE file at https://angular.io/license */ -import {Location} from '../../src/location/location'; +import {Location} from '@angular/common'; -{ - const baseUrl = '/base'; +const baseUrl = '/base'; - describe('Location Class', () => { - describe('stripTrailingSlash', () => { - it('should strip single character slash', () => { - const input = '/'; - expect(Location.stripTrailingSlash(input)).toBe(''); - }); +describe('Location Class', () => { + describe('stripTrailingSlash', () => { + it('should strip single character slash', () => { + const input = '/'; + expect(Location.stripTrailingSlash(input)).toBe(''); + }); - it('should normalize strip a trailing slash', () => { - const input = baseUrl + '/'; - expect(Location.stripTrailingSlash(input)).toBe(baseUrl); - }); + it('should normalize strip a trailing slash', () => { + const input = baseUrl + '/'; + expect(Location.stripTrailingSlash(input)).toBe(baseUrl); + }); - it('should ignore query params when stripping a slash', () => { - const input = baseUrl + '/?param=1'; - expect(Location.stripTrailingSlash(input)).toBe(baseUrl + '?param=1'); - }); + it('should ignore query params when stripping a slash', () => { + const input = baseUrl + '/?param=1'; + expect(Location.stripTrailingSlash(input)).toBe(baseUrl + '?param=1'); + }); - it('should not remove slashes inside query params', () => { - const input = baseUrl + '?test/?=3'; - expect(Location.stripTrailingSlash(input)).toBe(input); - }); + it('should not remove slashes inside query params', () => { + const input = baseUrl + '?test/?=3'; + expect(Location.stripTrailingSlash(input)).toBe(input); + }); - it('should not remove slashes after a pound sign', () => { - const input = baseUrl + '#test/?=3'; - expect(Location.stripTrailingSlash(input)).toBe(input); - }); + it('should not remove slashes after a pound sign', () => { + const input = baseUrl + '#test/?=3'; + expect(Location.stripTrailingSlash(input)).toBe(input); }); }); -} \ No newline at end of file +}); \ No newline at end of file diff --git a/packages/common/test/pipes/keyvalue_pipe_spec.ts b/packages/common/test/pipes/keyvalue_pipe_spec.ts index 484531dd9e..e9f1c53bfc 100644 --- a/packages/common/test/pipes/keyvalue_pipe_spec.ts +++ b/packages/common/test/pipes/keyvalue_pipe_spec.ts @@ -7,13 +7,8 @@ */ import {KeyValuePipe} from '@angular/common'; -import {EventEmitter, KeyValueDiffers, WrappedValue, ɵdefaultKeyValueDiffers as defaultKeyValueDiffers} from '@angular/core'; -import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {browserDetection} from '@angular/platform-browser/testing/src/browser_util'; - -import {defaultComparator} from '../../src/pipes/keyvalue_pipe'; -import {SpyChangeDetectorRef} from '../spies'; +import {defaultComparator} from '@angular/common/src/pipes/keyvalue_pipe'; +import {ɵdefaultKeyValueDiffers as defaultKeyValueDiffers} from '@angular/core'; describe('KeyValuePipe', () => { it('should return null when given null', () => {