test(ivy): update root causes for @angular/core TestBed failures (#27370)

PR Close #27370
This commit is contained in:
Pawel Kozlowski 2018-11-30 17:14:53 +01:00 committed by Igor Minar
parent eb17502a7c
commit 1fa5478fef
7 changed files with 715 additions and 752 deletions

View File

@ -135,7 +135,7 @@ class SomeComponent {
describe('ApplicationRef', () => { describe('ApplicationRef', () => {
beforeEach(() => { TestBed.configureTestingModule({imports: [createModule()]}); }); beforeEach(() => { TestBed.configureTestingModule({imports: [createModule()]}); });
fixmeIvy('unknown') && it('should throw when reentering tick', () => { it('should throw when reentering tick', () => {
@Component({template: '{{reenter()}}'}) @Component({template: '{{reenter()}}'})
class ReenteringComponent { class ReenteringComponent {
reenterCount = 1; reenterCount = 1;
@ -185,22 +185,19 @@ class SomeComponent {
}); });
describe('bootstrap', () => { describe('bootstrap', () => {
fixmeIvy('unknown') && it('should throw if an APP_INITIIALIZER is not yet resolved',
it('should throw if an APP_INITIIALIZER is not yet resolved', withModule(
withModule( {
{ providers: [
providers: [{ {provide: APP_INITIALIZER, useValue: () => new Promise(() => {}), multi: true}
provide: APP_INITIALIZER, ]
useValue: () => new Promise(() => {}), },
multi: true inject([ApplicationRef], (ref: ApplicationRef) => {
}] createRootEl();
}, expect(() => ref.bootstrap(SomeComponent))
inject([ApplicationRef], (ref: ApplicationRef) => { .toThrowError(
createRootEl(); 'Cannot bootstrap as there are still asynchronous initializers running. Bootstrap components in the `ngDoBootstrap` method of the root module.');
expect(() => ref.bootstrap(SomeComponent)) })));
.toThrowError(
'Cannot bootstrap as there are still asynchronous initializers running. Bootstrap components in the `ngDoBootstrap` method of the root module.');
})));
}); });
}); });
@ -211,112 +208,99 @@ class SomeComponent {
defaultPlatform = _platform; defaultPlatform = _platform;
})); }));
fixmeIvy('unknown') && it('should wait for asynchronous app initializers', async(() => {
it('should wait for asynchronous app initializers', async(() => { let resolve: (result: any) => void;
let resolve: (result: any) => void; const promise: Promise<any> = new Promise((res) => { resolve = res; });
const promise: Promise<any> = new Promise((res) => { resolve = res; }); let initializerDone = false;
let initializerDone = false; setTimeout(() => {
setTimeout(() => { resolve(true);
resolve(true); initializerDone = true;
initializerDone = true; }, 1);
}, 1);
defaultPlatform defaultPlatform
.bootstrapModule(createModule( .bootstrapModule(
[{provide: APP_INITIALIZER, useValue: () => promise, multi: true}])) createModule([{provide: APP_INITIALIZER, useValue: () => promise, multi: true}]))
.then(_ => { expect(initializerDone).toBe(true); }); .then(_ => { expect(initializerDone).toBe(true); });
})); }));
fixmeIvy('unknown') && it('should rethrow sync errors even if the exceptionHandler is not rethrowing', async(() => {
it('should rethrow sync errors even if the exceptionHandler is not rethrowing', defaultPlatform
async(() => { .bootstrapModule(createModule(
defaultPlatform [{provide: APP_INITIALIZER, useValue: () => { throw 'Test'; }, multi: true}]))
.bootstrapModule(createModule([ .then(() => expect(false).toBe(true), (e) => {
{provide: APP_INITIALIZER, useValue: () => { throw 'Test'; }, multi: true} expect(e).toBe('Test');
])) // Error rethrown will be seen by the exception handler since it's after
.then(() => expect(false).toBe(true), (e) => { // construction.
expect(e).toBe('Test'); expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
// Error rethrown will be seen by the exception handler since it's after });
// construction. }));
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
});
}));
fixmeIvy('unknown') && it('should rethrow promise errors even if the exceptionHandler is not rethrowing',
it('should rethrow promise errors even if the exceptionHandler is not rethrowing', async(() => {
async(() => { defaultPlatform
defaultPlatform .bootstrapModule(createModule([
.bootstrapModule(createModule([{ {provide: APP_INITIALIZER, useValue: () => Promise.reject('Test'), multi: true}
provide: APP_INITIALIZER, ]))
useValue: () => Promise.reject('Test'), .then(() => expect(false).toBe(true), (e) => {
multi: true expect(e).toBe('Test');
}])) expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
.then(() => expect(false).toBe(true), (e) => { });
expect(e).toBe('Test'); }));
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
});
}));
fixmeIvy('unknown') && it('should throw useful error when ApplicationRef is not configured', async(() => {
it('should throw useful error when ApplicationRef is not configured', async(() => { @NgModule()
@NgModule() class EmptyModule {
class EmptyModule { }
}
return defaultPlatform.bootstrapModule(EmptyModule) return defaultPlatform.bootstrapModule(EmptyModule)
.then(() => fail('expecting error'), (error) => { .then(() => fail('expecting error'), (error) => {
expect(error.message) expect(error.message)
.toEqual('No ErrorHandler. Is platform module (BrowserModule) included?'); .toEqual('No ErrorHandler. Is platform module (BrowserModule) included?');
}); });
})); }));
fixmeIvy('unknown') && it('should call the `ngDoBootstrap` method with `ApplicationRef` on the main module',
it('should call the `ngDoBootstrap` method with `ApplicationRef` on the main module', async(() => {
async(() => { const ngDoBootstrap = jasmine.createSpy('ngDoBootstrap');
const ngDoBootstrap = jasmine.createSpy('ngDoBootstrap'); defaultPlatform.bootstrapModule(createModule({ngDoBootstrap: ngDoBootstrap}))
defaultPlatform.bootstrapModule(createModule({ngDoBootstrap: ngDoBootstrap})) .then((moduleRef) => {
.then((moduleRef) => { const appRef = moduleRef.injector.get(ApplicationRef);
const appRef = moduleRef.injector.get(ApplicationRef); expect(ngDoBootstrap).toHaveBeenCalledWith(appRef);
expect(ngDoBootstrap).toHaveBeenCalledWith(appRef); });
}); }));
}));
fixmeIvy('unknown') && it('should auto bootstrap components listed in @NgModule.bootstrap', async(() => {
it('should auto bootstrap components listed in @NgModule.bootstrap', async(() => { defaultPlatform.bootstrapModule(createModule({bootstrap: [SomeComponent]}))
defaultPlatform.bootstrapModule(createModule({bootstrap: [SomeComponent]})) .then((moduleRef) => {
.then((moduleRef) => { const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef); expect(appRef.componentTypes).toEqual([SomeComponent]);
expect(appRef.componentTypes).toEqual([SomeComponent]); });
}); }));
}));
fixmeIvy('unknown') && it('should error if neither `ngDoBootstrap` nor @NgModule.bootstrap was specified',
it('should error if neither `ngDoBootstrap` nor @NgModule.bootstrap was specified', async(() => {
async(() => { defaultPlatform.bootstrapModule(createModule({ngDoBootstrap: false}))
defaultPlatform.bootstrapModule(createModule({ngDoBootstrap: false})) .then(() => expect(false).toBe(true), (e) => {
.then(() => expect(false).toBe(true), (e) => { const expectedErrMsg =
const expectedErrMsg = `The module MyModule was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. Please define one of these.`;
`The module MyModule was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. Please define one of these.`; expect(e.message).toEqual(expectedErrMsg);
expect(e.message).toEqual(expectedErrMsg); expect(mockConsole.res[0].join('#')).toEqual('ERROR#Error: ' + expectedErrMsg);
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Error: ' + expectedErrMsg); });
}); }));
}));
fixmeIvy('unknown') && it('should add bootstrapped module into platform modules list', async(() => {
it('should add bootstrapped module into platform modules list', async(() => { defaultPlatform.bootstrapModule(createModule({bootstrap: [SomeComponent]}))
defaultPlatform.bootstrapModule(createModule({bootstrap: [SomeComponent]})) .then(module => expect((<any>defaultPlatform)._modules).toContain(module));
.then(module => expect((<any>defaultPlatform)._modules).toContain(module)); }));
}));
fixmeIvy('unknown') && it('should bootstrap with NoopNgZone', async(() => {
it('should bootstrap with NoopNgZone', async(() => { defaultPlatform
defaultPlatform .bootstrapModule(createModule({bootstrap: [SomeComponent]}), {ngZone: 'noop'})
.bootstrapModule(createModule({bootstrap: [SomeComponent]}), {ngZone: 'noop'}) .then((module) => {
.then((module) => { const ngZone = module.injector.get(NgZone);
const ngZone = module.injector.get(NgZone); expect(ngZone instanceof NoopNgZone).toBe(true);
expect(ngZone instanceof NoopNgZone).toBe(true); });
}); }));
}));
}); });
describe('bootstrapModuleFactory', () => { describe('bootstrapModuleFactory', () => {
@ -325,58 +309,47 @@ class SomeComponent {
createRootEl(); createRootEl();
defaultPlatform = _platform; defaultPlatform = _platform;
})); }));
fixmeIvy('unknown') && it('should wait for asynchronous app initializers', async(() => {
it('should wait for asynchronous app initializers', async(() => { let resolve: (result: any) => void;
let resolve: (result: any) => void; const promise: Promise<any> = new Promise((res) => { resolve = res; });
const promise: Promise<any> = new Promise((res) => { resolve = res; }); let initializerDone = false;
let initializerDone = false; setTimeout(() => {
setTimeout(() => { resolve(true);
resolve(true); initializerDone = true;
initializerDone = true; }, 1);
}, 1);
const compilerFactory: CompilerFactory = const compilerFactory: CompilerFactory =
defaultPlatform.injector.get(CompilerFactory, null); defaultPlatform.injector.get(CompilerFactory, null);
const moduleFactory = const moduleFactory = compilerFactory.createCompiler().compileModuleSync(
compilerFactory.createCompiler().compileModuleSync(createModule( createModule([{provide: APP_INITIALIZER, useValue: () => promise, multi: true}]));
[{provide: APP_INITIALIZER, useValue: () => promise, multi: true}])); defaultPlatform.bootstrapModuleFactory(moduleFactory).then(_ => {
defaultPlatform.bootstrapModuleFactory(moduleFactory).then(_ => { expect(initializerDone).toBe(true);
expect(initializerDone).toBe(true); });
}));
it('should rethrow sync errors even if the exceptionHandler is not rethrowing', async(() => {
const compilerFactory: CompilerFactory =
defaultPlatform.injector.get(CompilerFactory, null);
const moduleFactory = compilerFactory.createCompiler().compileModuleSync(createModule(
[{provide: APP_INITIALIZER, useValue: () => { throw 'Test'; }, multi: true}]));
expect(() => defaultPlatform.bootstrapModuleFactory(moduleFactory)).toThrow('Test');
// Error rethrown will be seen by the exception handler since it's after
// construction.
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
}));
it('should rethrow promise errors even if the exceptionHandler is not rethrowing',
async(() => {
const compilerFactory: CompilerFactory =
defaultPlatform.injector.get(CompilerFactory, null);
const moduleFactory = compilerFactory.createCompiler().compileModuleSync(createModule(
[{provide: APP_INITIALIZER, useValue: () => Promise.reject('Test'), multi: true}]));
defaultPlatform.bootstrapModuleFactory(moduleFactory)
.then(() => expect(false).toBe(true), (e) => {
expect(e).toBe('Test');
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
}); });
})); }));
fixmeIvy('unknown') &&
it('should rethrow sync errors even if the exceptionHandler is not rethrowing',
async(() => {
const compilerFactory: CompilerFactory =
defaultPlatform.injector.get(CompilerFactory, null);
const moduleFactory =
compilerFactory.createCompiler().compileModuleSync(createModule([
{provide: APP_INITIALIZER, useValue: () => { throw 'Test'; }, multi: true}
]));
expect(() => defaultPlatform.bootstrapModuleFactory(moduleFactory)).toThrow('Test');
// Error rethrown will be seen by the exception handler since it's after
// construction.
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
}));
fixmeIvy('unknown') &&
it('should rethrow promise errors even if the exceptionHandler is not rethrowing',
async(() => {
const compilerFactory: CompilerFactory =
defaultPlatform.injector.get(CompilerFactory, null);
const moduleFactory =
compilerFactory.createCompiler().compileModuleSync(createModule([{
provide: APP_INITIALIZER,
useValue: () => Promise.reject('Test'),
multi: true
}]));
defaultPlatform.bootstrapModuleFactory(moduleFactory)
.then(() => expect(false).toBe(true), (e) => {
expect(e).toBe('Test');
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Test');
});
}));
}); });
describe('attachView / detachView', () => { describe('attachView / detachView', () => {
@ -565,22 +538,20 @@ class SomeComponent {
}); });
} }
fixmeIvy('unknown') && it('isStable should fire on synchronous component loading', it('isStable should fire on synchronous component loading',
async(() => { expectStableTexts(SyncComp, ['1']); })); async(() => { expectStableTexts(SyncComp, ['1']); }));
fixmeIvy('unknown') && it('isStable should fire after a microtask on init is completed', it('isStable should fire after a microtask on init is completed',
async(() => { expectStableTexts(MicroTaskComp, ['11']); })); async(() => { expectStableTexts(MicroTaskComp, ['11']); }));
fixmeIvy('unknown') && it('isStable should fire after a macrotask on init is completed', it('isStable should fire after a macrotask on init is completed',
async(() => { expectStableTexts(MacroTaskComp, ['11']); })); async(() => { expectStableTexts(MacroTaskComp, ['11']); }));
fixmeIvy('unknown') && it('isStable should fire only after chain of micro and macrotasks on init are completed',
it('isStable should fire only after chain of micro and macrotasks on init are completed', async(() => { expectStableTexts(MicroMacroTaskComp, ['111']); }));
async(() => { expectStableTexts(MicroMacroTaskComp, ['111']); }));
fixmeIvy('unknown') && it('isStable should fire only after chain of macro and microtasks on init are completed',
it('isStable should fire only after chain of macro and microtasks on init are completed', async(() => { expectStableTexts(MacroMicroTaskComp, ['111']); }));
async(() => { expectStableTexts(MacroMicroTaskComp, ['111']); }));
describe('unstable', () => { describe('unstable', () => {
let unstableCalled = false; let unstableCalled = false;
@ -601,19 +572,19 @@ class SomeComponent {
}); });
} }
fixmeIvy('unknown') && it('should be fired after app becomes unstable', async(() => { it('should be fired after app becomes unstable', async(() => {
const fixture = TestBed.createComponent(ClickComp); const fixture = TestBed.createComponent(ClickComp);
const appRef: ApplicationRef = TestBed.get(ApplicationRef); const appRef: ApplicationRef = TestBed.get(ApplicationRef);
const zone: NgZone = TestBed.get(NgZone); const zone: NgZone = TestBed.get(NgZone);
appRef.attachView(fixture.componentRef.hostView); appRef.attachView(fixture.componentRef.hostView);
zone.run(() => appRef.tick()); zone.run(() => appRef.tick());
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expectUnstable(appRef); expectUnstable(appRef);
const element = fixture.debugElement.children[0]; const element = fixture.debugElement.children[0];
dispatchEvent(element.nativeElement, 'click'); dispatchEvent(element.nativeElement, 'click');
}); });
})); }));
}); });
}); });
} }

View File

@ -10,7 +10,6 @@ import {Component, Injectable, Input} from '@angular/core';
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBed, async, withModule} from '@angular/core/testing'; import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBed, async, withModule} from '@angular/core/testing';
import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util'; import {dispatchEvent} from '@angular/platform-browser/testing/src/browser_util';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {fixmeIvy} from '@angular/private/testing';
@Component({selector: 'simple-comp', template: `<span>Original {{simpleBinding}}</span>`}) @Component({selector: 'simple-comp', template: `<span>Original {{simpleBinding}}</span>`})
@Injectable() @Injectable()
@ -94,7 +93,7 @@ class NestedAsyncTimeoutComp {
}); });
})); }));
fixmeIvy('unknown') && it('should auto detect changes if autoDetectChanges is called', () => { it('should auto detect changes if autoDetectChanges is called', () => {
const componentFixture = TestBed.createComponent(AutoDetectComp); const componentFixture = TestBed.createComponent(AutoDetectComp);
expect(componentFixture.ngZone).not.toBeNull(); expect(componentFixture.ngZone).not.toBeNull();
@ -108,192 +107,181 @@ class NestedAsyncTimeoutComp {
expect(componentFixture.nativeElement).toHaveText('11'); expect(componentFixture.nativeElement).toHaveText('11');
}); });
fixmeIvy('unknown') && it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
it('should auto detect changes if ComponentFixtureAutoDetect is provided as true', withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => {
withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => {
const componentFixture = TestBed.createComponent(AutoDetectComp); const componentFixture = TestBed.createComponent(AutoDetectComp);
expect(componentFixture.nativeElement).toHaveText('1'); expect(componentFixture.nativeElement).toHaveText('1');
const element = componentFixture.debugElement.children[0]; const element = componentFixture.debugElement.children[0];
dispatchEvent(element.nativeElement, 'click'); 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'); 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', () => { describe('No NgZone', () => {
beforeEach(() => { beforeEach(() => {
@ -301,7 +289,7 @@ class NestedAsyncTimeoutComp {
{providers: [{provide: ComponentFixtureNoNgZone, useValue: true}]}); {providers: [{provide: ComponentFixtureNoNgZone, useValue: true}]});
}); });
fixmeIvy('unknown') && it('calling autoDetectChanges raises an error', () => { it('calling autoDetectChanges raises an error', () => {
const componentFixture = TestBed.createComponent(SimpleComp); const componentFixture = TestBed.createComponent(SimpleComp);
expect(() => { expect(() => {
@ -309,28 +297,27 @@ class NestedAsyncTimeoutComp {
}).toThrowError(/Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set/); }).toThrowError(/Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set/);
}); });
fixmeIvy('unknown') && it('should instantiate a component with valid DOM', async(() => {
it('should instantiate a component with valid DOM', async(() => {
const componentFixture = TestBed.createComponent(SimpleComp); const componentFixture = TestBed.createComponent(SimpleComp);
expect(componentFixture.ngZone).toBeNull(); expect(componentFixture.ngZone).toBeNull();
componentFixture.detectChanges(); componentFixture.detectChanges();
expect(componentFixture.nativeElement).toHaveText('Original Simple'); expect(componentFixture.nativeElement).toHaveText('Original Simple');
})); }));
fixmeIvy('unknown') && it('should allow changing members of the component', async(() => { it('should allow changing members of the component', async(() => {
const componentFixture = TestBed.createComponent(MyIfComp); const componentFixture = TestBed.createComponent(MyIfComp);
componentFixture.detectChanges(); componentFixture.detectChanges();
expect(componentFixture.nativeElement).toHaveText('MyIf()'); expect(componentFixture.nativeElement).toHaveText('MyIf()');
componentFixture.componentInstance.showMore = true; componentFixture.componentInstance.showMore = true;
componentFixture.detectChanges(); componentFixture.detectChanges();
expect(componentFixture.nativeElement).toHaveText('MyIf(More)'); expect(componentFixture.nativeElement).toHaveText('MyIf(More)');
})); }));
}); });
}); });

View File

@ -192,13 +192,13 @@ class TestApp {
}); });
})); }));
fixmeIvy('unknown') && it('should list all child nodes', () => { it('should list all child nodes', () => {
fixture = TestBed.createComponent(ParentComp); fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges(); fixture.detectChanges();
expect(fixture.debugElement.childNodes.length).toEqual(3); expect(fixture.debugElement.childNodes.length).toEqual(3);
}); });
fixmeIvy('unknown') && it('should list all component child elements', () => { it('should list all component child elements', () => {
fixture = TestBed.createComponent(ParentComp); fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges(); fixture.detectChanges();
const childEls = fixture.debugElement.children; const childEls = fixture.debugElement.children;
@ -225,7 +225,7 @@ class TestApp {
expect(getDOM().hasClass(childNested[0].nativeElement, 'childnested')).toBe(true); expect(getDOM().hasClass(childNested[0].nativeElement, 'childnested')).toBe(true);
}); });
fixmeIvy('unknown') && it('should list conditional component child elements', () => { it('should list conditional component child elements', () => {
fixture = TestBed.createComponent(ConditionalParentComp); fixture = TestBed.createComponent(ConditionalParentComp);
fixture.detectChanges(); fixture.detectChanges();
@ -246,7 +246,7 @@ class TestApp {
expect(conditionalContentComp.children.length).toEqual(1); expect(conditionalContentComp.children.length).toEqual(1);
}); });
fixmeIvy('unknown') && it('should list child elements within viewports', () => { it('should list child elements within viewports', () => {
fixture = TestBed.createComponent(UsingFor); fixture = TestBed.createComponent(UsingFor);
fixture.detectChanges(); fixture.detectChanges();
@ -259,34 +259,37 @@ class TestApp {
expect(list.children.length).toEqual(3); expect(list.children.length).toEqual(3);
}); });
fixmeIvy('unknown') && it('should list element attributes', () => { fixmeIvy('FW-719: DebugElement needs proper implementation of its methods.') &&
fixture = TestBed.createComponent(TestApp); it('should list element attributes', () => {
fixture.detectChanges(); fixture = TestBed.createComponent(TestApp);
const bankElem = fixture.debugElement.children[0]; fixture.detectChanges();
const bankElem = fixture.debugElement.children[0];
expect(bankElem.attributes['bank']).toEqual('RBC'); expect(bankElem.attributes['bank']).toEqual('RBC');
expect(bankElem.attributes['account']).toEqual('4747'); expect(bankElem.attributes['account']).toEqual('4747');
}); });
fixmeIvy('unknown') && it('should list element classes', () => { fixmeIvy('FW-719: DebugElement needs proper implementation of its methods.') &&
fixture = TestBed.createComponent(TestApp); it('should list element classes', () => {
fixture.detectChanges(); fixture = TestBed.createComponent(TestApp);
const bankElem = fixture.debugElement.children[0]; fixture.detectChanges();
const bankElem = fixture.debugElement.children[0];
expect(bankElem.classes['closed']).toBe(true); expect(bankElem.classes['closed']).toBe(true);
expect(bankElem.classes['open']).toBe(false); expect(bankElem.classes['open']).toBe(false);
}); });
fixmeIvy('unknown') && it('should list element styles', () => { fixmeIvy('FW-719: DebugElement needs proper implementation of its methods.') &&
fixture = TestBed.createComponent(TestApp); it('should list element styles', () => {
fixture.detectChanges(); fixture = TestBed.createComponent(TestApp);
const bankElem = fixture.debugElement.children[0]; fixture.detectChanges();
const bankElem = fixture.debugElement.children[0];
expect(bankElem.styles['width']).toEqual('200px'); expect(bankElem.styles['width']).toEqual('200px');
expect(bankElem.styles['color']).toEqual('red'); expect(bankElem.styles['color']).toEqual('red');
}); });
fixmeIvy('unknown') && it('should query child elements by css', () => { it('should query child elements by css', () => {
fixture = TestBed.createComponent(ParentComp); fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges(); fixture.detectChanges();
@ -296,7 +299,7 @@ class TestApp {
expect(getDOM().hasClass(childTestEls[0].nativeElement, 'child-comp-class')).toBe(true); expect(getDOM().hasClass(childTestEls[0].nativeElement, 'child-comp-class')).toBe(true);
}); });
fixmeIvy('unknown') && it('should query child elements by directive', () => { it('should query child elements by directive', () => {
fixture = TestBed.createComponent(ParentComp); fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges(); fixture.detectChanges();
@ -309,39 +312,42 @@ class TestApp {
expect(getDOM().hasClass(childTestEls[3].nativeElement, 'childnested')).toBe(true); expect(getDOM().hasClass(childTestEls[3].nativeElement, 'childnested')).toBe(true);
}); });
fixmeIvy('unknown') && it('should list providerTokens', () => { fixmeIvy('FW-719: DebugElement needs proper implementation of its methods.') &&
fixture = TestBed.createComponent(ParentComp); it('should list providerTokens', () => {
fixture.detectChanges(); fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
expect(fixture.debugElement.providerTokens).toContain(Logger); expect(fixture.debugElement.providerTokens).toContain(Logger);
}); });
fixmeIvy('unknown') && it('should list locals', () => { it('should list locals', () => {
fixture = TestBed.createComponent(LocalsComp); fixture = TestBed.createComponent(LocalsComp);
fixture.detectChanges(); fixture.detectChanges();
expect(fixture.debugElement.children[0].references !['alice']).toBeAnInstanceOf(MyDir); expect(fixture.debugElement.children[0].references !['alice']).toBeAnInstanceOf(MyDir);
}); });
fixmeIvy('unknown') && it('should allow injecting from the element injector', () => { fixmeIvy('FW-719: DebugElement needs proper implementation of its methods.') &&
fixture = TestBed.createComponent(ParentComp); it('should allow injecting from the element injector', () => {
fixture.detectChanges(); fixture = TestBed.createComponent(ParentComp);
fixture.detectChanges();
expect((<Logger>(fixture.debugElement.children[0].injector.get(Logger))).logs).toEqual([ expect((<Logger>(fixture.debugElement.children[0].injector.get(Logger))).logs).toEqual([
'parent', 'nestedparent', 'child', 'nestedchild' 'parent', 'nestedparent', 'child', 'nestedchild'
]); ]);
}); });
fixmeIvy('unknown') && it('should list event listeners', () => { fixmeIvy('FW-719: DebugElement needs proper implementation of its methods.') &&
fixture = TestBed.createComponent(EventsComp); it('should list event listeners', () => {
fixture.detectChanges(); fixture = TestBed.createComponent(EventsComp);
fixture.detectChanges();
expect(fixture.debugElement.children[0].listeners.length).toEqual(1); expect(fixture.debugElement.children[0].listeners.length).toEqual(1);
expect(fixture.debugElement.children[1].listeners.length).toEqual(1); expect(fixture.debugElement.children[1].listeners.length).toEqual(1);
}); });
fixmeIvy('unknown') && it('should trigger event handlers', () => { it('should trigger event handlers', () => {
fixture = TestBed.createComponent(EventsComp); fixture = TestBed.createComponent(EventsComp);
fixture.detectChanges(); fixture.detectChanges();

View File

@ -19,14 +19,14 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
{ {
describe('fake async', () => { describe('fake async', () => {
fixmeIvy('unknown') && it('should run synchronous code', () => { it('should run synchronous code', () => {
let ran = false; let ran = false;
fakeAsync(() => { ran = true; })(); fakeAsync(() => { ran = true; })();
expect(ran).toEqual(true); expect(ran).toEqual(true);
}); });
fixmeIvy('unknown') && it('should pass arguments to the wrapped function', () => { it('should pass arguments to the wrapped function', () => {
fakeAsync((foo: any /** TODO #9100 */, bar: any /** TODO #9100 */) => { fakeAsync((foo: any /** TODO #9100 */, bar: any /** TODO #9100 */) => {
expect(foo).toEqual('foo'); expect(foo).toEqual('foo');
expect(bar).toEqual('bar'); expect(bar).toEqual('bar');
@ -38,13 +38,13 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
expect(parser).toBeAnInstanceOf(Parser); expect(parser).toBeAnInstanceOf(Parser);
}))); })));
fixmeIvy('unknown') && it('should throw on nested calls', () => { it('should throw on nested calls', () => {
expect(() => { expect(() => {
fakeAsync(() => { fakeAsync((): any /** TODO #9100 */ => null)(); })(); fakeAsync(() => { fakeAsync((): any /** TODO #9100 */ => null)(); })();
}).toThrowError('fakeAsync() calls can not be nested'); }).toThrowError('fakeAsync() calls can not be nested');
}); });
fixmeIvy('unknown') && it('should flush microtasks before returning', () => { it('should flush microtasks before returning', () => {
let thenRan = false; let thenRan = false;
fakeAsync(() => { resolvedPromise.then(_ => { thenRan = true; }); })(); fakeAsync(() => { resolvedPromise.then(_ => { thenRan = true; }); })();
@ -53,280 +53,275 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
}); });
fixmeIvy('unknown') && it('should propagate the return value', it('should propagate the return value',
() => { expect(fakeAsync(() => 'foo')()).toEqual('foo'); }); () => { expect(fakeAsync(() => 'foo')()).toEqual('foo'); });
describe('Promise', () => { describe('Promise', () => {
fixmeIvy('unknown') && it('should run asynchronous code', fakeAsync(() => { it('should run asynchronous code', fakeAsync(() => {
let thenRan = false; let thenRan = false;
resolvedPromise.then((_) => { thenRan = true; }); resolvedPromise.then((_) => { thenRan = true; });
expect(thenRan).toEqual(false); expect(thenRan).toEqual(false);
flushMicrotasks(); flushMicrotasks();
expect(thenRan).toEqual(true); expect(thenRan).toEqual(true);
})); }));
fixmeIvy('unknown') && it('should run chained thens', fakeAsync(() => { it('should run chained thens', fakeAsync(() => {
const log = new Log(); 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(); flushMicrotasks();
expect(log.result()).toEqual('1; 2'); expect(log.result()).toEqual('1; 2');
})); }));
fixmeIvy('unknown') && it('should run Promise created in Promise', fakeAsync(() => { it('should run Promise created in Promise', fakeAsync(() => {
const log = new Log(); const log = new Log();
resolvedPromise.then((_) => { resolvedPromise.then((_) => {
log.add(1); log.add(1);
resolvedPromise.then((_) => log.add(2)); resolvedPromise.then((_) => log.add(2));
}); });
expect(log.result()).toEqual(''); expect(log.result()).toEqual('');
flushMicrotasks(); flushMicrotasks();
expect(log.result()).toEqual('1; 2'); expect(log.result()).toEqual('1; 2');
})); }));
fixmeIvy('unknown') && it('should complain if the test throws an exception during async calls', () => {
it('should complain if the test throws an exception during async calls', () => { expect(() => {
expect(() => { fakeAsync(() => {
fakeAsync(() => { resolvedPromise.then((_) => { throw new Error('async'); });
resolvedPromise.then((_) => { throw new Error('async'); }); flushMicrotasks();
flushMicrotasks(); })();
})(); }).toThrowError(/Uncaught \(in promise\): Error: async/);
}).toThrowError(/Uncaught \(in promise\): Error: async/); });
});
fixmeIvy('unknown') && it('should complain if a test throws an exception', () => { it('should complain if a test throws an exception', () => {
expect(() => { fakeAsync(() => { throw new Error('sync'); })(); }).toThrowError('sync'); expect(() => { fakeAsync(() => { throw new Error('sync'); })(); }).toThrowError('sync');
}); });
}); });
describe('timers', () => { describe('timers', () => {
fixmeIvy('unknown') && it('should run queued zero duration timer on zero tick', fakeAsync(() => {
it('should run queued zero duration timer on zero tick', fakeAsync(() => { let ran = false;
let ran = false; setTimeout(() => { ran = true; }, 0);
setTimeout(() => { ran = true; }, 0);
expect(ran).toEqual(false); expect(ran).toEqual(false);
tick(); tick();
expect(ran).toEqual(true); expect(ran).toEqual(true);
})); }));
fixmeIvy('unknown') && it('should run queued timer after sufficient clock ticks', fakeAsync(() => {
it('should run queued timer after sufficient clock ticks', fakeAsync(() => { let ran = false;
let ran = false; setTimeout(() => { ran = true; }, 10);
setTimeout(() => { ran = true; }, 10);
tick(6); tick(6);
expect(ran).toEqual(false); expect(ran).toEqual(false);
tick(6); tick(6);
expect(ran).toEqual(true); expect(ran).toEqual(true);
})); }));
fixmeIvy('unknown') && it('should run queued timer only once', fakeAsync(() => { it('should run queued timer only once', fakeAsync(() => {
let cycles = 0; let cycles = 0;
setTimeout(() => { cycles++; }, 10); setTimeout(() => { cycles++; }, 10);
tick(10); tick(10);
expect(cycles).toEqual(1); expect(cycles).toEqual(1);
tick(10); tick(10);
expect(cycles).toEqual(1); expect(cycles).toEqual(1);
tick(10); tick(10);
expect(cycles).toEqual(1); expect(cycles).toEqual(1);
})); }));
fixmeIvy('unknown') && it('should not run cancelled timer', fakeAsync(() => { it('should not run cancelled timer', fakeAsync(() => {
let ran = false; let ran = false;
const id = setTimeout(() => { ran = true; }, 10); const id = setTimeout(() => { ran = true; }, 10);
clearTimeout(id); clearTimeout(id);
tick(10); tick(10);
expect(ran).toEqual(false); expect(ran).toEqual(false);
})); }));
fixmeIvy('unknown') && it('should throw an error on dangling timers', () => { it('should throw an error on dangling timers', () => {
expect(() => { expect(() => {
fakeAsync(() => { setTimeout(() => {}, 10); })(); fakeAsync(() => { setTimeout(() => {}, 10); })();
}).toThrowError('1 timer(s) still in the queue.'); }).toThrowError('1 timer(s) still in the queue.');
}); });
fixmeIvy('unknown') && it('should throw an error on dangling periodic timers', () => { it('should throw an error on dangling periodic timers', () => {
expect(() => { expect(() => {
fakeAsync(() => { setInterval(() => {}, 10); })(); fakeAsync(() => { setInterval(() => {}, 10); })();
}).toThrowError('1 periodic timer(s) still in the queue.'); }).toThrowError('1 periodic timer(s) still in the queue.');
}); });
fixmeIvy('unknown') && it('should run periodic timers', fakeAsync(() => { it('should run periodic timers', fakeAsync(() => {
let cycles = 0; let cycles = 0;
const id = setInterval(() => { cycles++; }, 10); const id = setInterval(() => { cycles++; }, 10);
tick(10); tick(10);
expect(cycles).toEqual(1); expect(cycles).toEqual(1);
tick(10); tick(10);
expect(cycles).toEqual(2); expect(cycles).toEqual(2);
tick(10); tick(10);
expect(cycles).toEqual(3); expect(cycles).toEqual(3);
clearInterval(id); clearInterval(id);
})); }));
fixmeIvy('unknown') && it('should not run cancelled periodic timer', fakeAsync(() => { it('should not run cancelled periodic timer', fakeAsync(() => {
let ran = false; let ran = false;
const id = setInterval(() => { ran = true; }, 10); const id = setInterval(() => { ran = true; }, 10);
clearInterval(id); clearInterval(id);
tick(10); tick(10);
expect(ran).toEqual(false); expect(ran).toEqual(false);
})); }));
fixmeIvy('unknown') && it('should be able to cancel periodic timers from a callback', fakeAsync(() => {
it('should be able to cancel periodic timers from a callback', fakeAsync(() => { let cycles = 0;
let cycles = 0; let id: any /** TODO #9100 */;
let id: any /** TODO #9100 */;
id = setInterval(() => { id = setInterval(() => {
cycles++; cycles++;
clearInterval(id); clearInterval(id);
}, 10); }, 10);
tick(10); tick(10);
expect(cycles).toEqual(1); expect(cycles).toEqual(1);
tick(10); tick(10);
expect(cycles).toEqual(1); expect(cycles).toEqual(1);
})); }));
fixmeIvy('unknown') && it('should clear periodic timers', fakeAsync(() => { it('should clear periodic timers', fakeAsync(() => {
let cycles = 0; let cycles = 0;
const id = setInterval(() => { cycles++; }, 10); const id = setInterval(() => { cycles++; }, 10);
tick(10); tick(10);
expect(cycles).toEqual(1); expect(cycles).toEqual(1);
discardPeriodicTasks(); discardPeriodicTasks();
// Tick once to clear out the timer which already started. // Tick once to clear out the timer which already started.
tick(10); tick(10);
expect(cycles).toEqual(2); expect(cycles).toEqual(2);
tick(10); tick(10);
// Nothing should change // Nothing should change
expect(cycles).toEqual(2); expect(cycles).toEqual(2);
})); }));
fixmeIvy('unknown') && it('should process microtasks before timers', fakeAsync(() => { it('should process microtasks before timers', fakeAsync(() => {
const log = new Log(); 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); tick(10);
expect(log.result()).toEqual('microtask; timer; periodic timer'); expect(log.result()).toEqual('microtask; timer; periodic timer');
clearInterval(id); clearInterval(id);
})); }));
fixmeIvy('unknown') && it('should process micro-tasks created in timers before next timers', fakeAsync(() => {
it('should process micro-tasks created in timers before next timers', fakeAsync(() => { const log = new Log();
const log = new Log();
resolvedPromise.then((_) => log.add('microtask')); resolvedPromise.then((_) => log.add('microtask'));
setTimeout(() => { setTimeout(() => {
log.add('timer'); log.add('timer');
resolvedPromise.then((_) => log.add('t microtask')); resolvedPromise.then((_) => log.add('t microtask'));
}, 9); }, 9);
const id = setInterval(() => { const id = setInterval(() => {
log.add('periodic timer'); log.add('periodic timer');
resolvedPromise.then((_) => log.add('pt microtask')); resolvedPromise.then((_) => log.add('pt microtask'));
}, 10); }, 10);
tick(10); tick(10);
expect(log.result()) expect(log.result())
.toEqual('microtask; timer; t microtask; periodic timer; pt microtask'); .toEqual('microtask; timer; t microtask; periodic timer; pt microtask');
tick(10); tick(10);
expect(log.result()) expect(log.result())
.toEqual( .toEqual(
'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask'); 'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask');
clearInterval(id); clearInterval(id);
})); }));
fixmeIvy('unknown') && it('should flush tasks', fakeAsync(() => { it('should flush tasks', fakeAsync(() => {
let ran = false; let ran = false;
setTimeout(() => { ran = true; }, 10); setTimeout(() => { ran = true; }, 10);
flush(); flush();
expect(ran).toEqual(true); expect(ran).toEqual(true);
})); }));
fixmeIvy('unknown') && it('should flush multiple tasks', fakeAsync(() => { it('should flush multiple tasks', fakeAsync(() => {
let ran = false; let ran = false;
let ran2 = false; let ran2 = false;
setTimeout(() => { ran = true; }, 10); setTimeout(() => { ran = true; }, 10);
setTimeout(() => { ran2 = true; }, 30); setTimeout(() => { ran2 = true; }, 30);
let elapsed = flush(); let elapsed = flush();
expect(ran).toEqual(true); expect(ran).toEqual(true);
expect(ran2).toEqual(true); expect(ran2).toEqual(true);
expect(elapsed).toEqual(30); expect(elapsed).toEqual(30);
})); }));
fixmeIvy('unknown') && it('should move periodic tasks', fakeAsync(() => { it('should move periodic tasks', fakeAsync(() => {
let ran = false; let ran = false;
let count = 0; let count = 0;
setInterval(() => { count++; }, 10); setInterval(() => { count++; }, 10);
setTimeout(() => { ran = true; }, 35); setTimeout(() => { ran = true; }, 35);
let elapsed = flush(); let elapsed = flush();
expect(count).toEqual(3); expect(count).toEqual(3);
expect(ran).toEqual(true); expect(ran).toEqual(true);
expect(elapsed).toEqual(35); expect(elapsed).toEqual(35);
discardPeriodicTasks(); discardPeriodicTasks();
})); }));
}); });
describe('outside of the fakeAsync zone', () => { describe('outside of the fakeAsync zone', () => {
fixmeIvy('unknown') && it('calling flushMicrotasks should throw', () => { it('calling flushMicrotasks should throw', () => {
expect(() => { expect(() => {
flushMicrotasks(); flushMicrotasks();
}).toThrowError('The code should be running in the fakeAsync zone to call this function'); }).toThrowError('The code should be running in the fakeAsync zone to call this function');
}); });
fixmeIvy('unknown') && it('calling tick should throw', () => { it('calling tick should throw', () => {
expect(() => { expect(() => {
tick(); tick();
}).toThrowError('The code should be running in the fakeAsync zone to call this function'); }).toThrowError('The code should be running in the fakeAsync zone to call this function');
}); });
fixmeIvy('unknown') && it('calling flush should throw', () => { it('calling flush should throw', () => {
expect(() => { expect(() => {
flush(); flush();
}).toThrowError('The code should be running in the fakeAsync zone to call this function'); }).toThrowError('The code should be running in the fakeAsync zone to call this function');
}); });
fixmeIvy('unknown') && it('calling discardPeriodicTasks should throw', () => { it('calling discardPeriodicTasks should throw', () => {
expect(() => { expect(() => {
discardPeriodicTasks(); discardPeriodicTasks();
}).toThrowError('The code should be running in the fakeAsync zone to call this function'); }).toThrowError('The code should be running in the fakeAsync zone to call this function');
@ -338,10 +333,10 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
let zoneInTest1: Zone; let zoneInTest1: Zone;
beforeEach(fakeAsync(() => { zoneInBeforeEach = Zone.current; })); beforeEach(fakeAsync(() => { zoneInBeforeEach = Zone.current; }));
fixmeIvy('unknown') && it('should use the same zone as in beforeEach', fakeAsync(() => { it('should use the same zone as in beforeEach', fakeAsync(() => {
zoneInTest1 = Zone.current; zoneInTest1 = Zone.current;
expect(zoneInTest1).toBe(zoneInBeforeEach); expect(zoneInTest1).toBe(zoneInBeforeEach);
})); }));
}); });
}); });
@ -350,21 +345,19 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
afterEach(() => { ProxyZoneSpec.assertPresent(); }); afterEach(() => { ProxyZoneSpec.assertPresent(); });
fixmeIvy('unknown') && it('should allow fakeAsync zone to retroactively set a zoneSpec outside of fakeAsync', () => {
it('should allow fakeAsync zone to retroactively set a zoneSpec outside of fakeAsync', ProxyZoneSpec.assertPresent();
() => { let state: string = 'not run';
ProxyZoneSpec.assertPresent(); const testZone = Zone.current.fork({name: 'test-zone'});
let state: string = 'not run'; (fakeAsync(() => {
const testZone = Zone.current.fork({name: 'test-zone'}); testZone.run(() => {
(fakeAsync(() => { Promise.resolve('works').then((v) => state = v);
testZone.run(() => { expect(state).toEqual('not run');
Promise.resolve('works').then((v) => state = v); flushMicrotasks();
expect(state).toEqual('not run'); expect(state).toEqual('works');
flushMicrotasks(); });
expect(state).toEqual('works'); }))();
}); expect(state).toEqual('works');
}))(); });
expect(state).toEqual('works');
});
}); });
} }

View File

@ -22,7 +22,7 @@ import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens'; import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
import {dispatchEvent, el} from '@angular/platform-browser/testing/src/browser_util'; import {dispatchEvent, el} from '@angular/platform-browser/testing/src/browser_util';
import {expect} from '@angular/platform-browser/testing/src/matchers'; import {expect} from '@angular/platform-browser/testing/src/matchers';
import {fixmeIvy} from '@angular/private/testing'; import {fixmeIvy, modifiedInIvy} from '@angular/private/testing';
import {stringify} from '../../src/util'; import {stringify} from '../../src/util';
@ -209,20 +209,21 @@ function declareTests(config?: {useJit: boolean}) {
.toEqual('Some other <div>HTML</div>'); .toEqual('Some other <div>HTML</div>');
}); });
fixmeIvy('unknown') && it('should consume binding to className using class alias', () => { modifiedInIvy('Binding to the class property directly works differently') &&
TestBed.configureTestingModule({declarations: [MyComp]}); it('should consume binding to className using class alias', () => {
const template = '<div class="initial" [class]="ctxProp"></div>'; TestBed.configureTestingModule({declarations: [MyComp]});
TestBed.overrideComponent(MyComp, {set: {template}}); const template = '<div class="initial" [class]="ctxProp"></div>';
const fixture = TestBed.createComponent(MyComp); TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
const nativeEl = fixture.debugElement.children[0].nativeElement; const nativeEl = fixture.debugElement.children[0].nativeElement;
fixture.componentInstance.ctxProp = 'foo bar'; fixture.componentInstance.ctxProp = 'foo bar';
fixture.detectChanges(); fixture.detectChanges();
expect(nativeEl).toHaveCssClass('foo'); expect(nativeEl).toHaveCssClass('foo');
expect(nativeEl).toHaveCssClass('bar'); expect(nativeEl).toHaveCssClass('bar');
expect(nativeEl).not.toHaveCssClass('initial'); expect(nativeEl).not.toHaveCssClass('initial');
}); });
it('should consume binding to htmlFor using for alias', () => { it('should consume binding to htmlFor using for alias', () => {
const template = '<label [for]="ctxProp"></label>'; const template = '<label [for]="ctxProp"></label>';
@ -373,7 +374,7 @@ function declareTests(config?: {useJit: boolean}) {
const fixture = TestBed.createComponent(MyComp); const fixture = TestBed.createComponent(MyComp);
}); });
fixmeIvy('FW-678: ivy generates different DOM structure for <ng-container>') && modifiedInIvy('Comment node order changed') &&
it('should support template directives via `<ng-template>` elements.', () => { it('should support template directives via `<ng-template>` elements.', () => {
TestBed.configureTestingModule({declarations: [MyComp, SomeViewport]}); TestBed.configureTestingModule({declarations: [MyComp, SomeViewport]});
const template = const template =
@ -401,7 +402,8 @@ function declareTests(config?: {useJit: boolean}) {
expect(fixture.nativeElement).toHaveText('baz'); expect(fixture.nativeElement).toHaveText('baz');
}); });
fixmeIvy('unknown') && fixmeIvy(
'FW-665: Discovery util fails with "Unable to find the given context data for the given target"') &&
it('should not detach views in ViewContainers when the parent view is destroyed.', () => { it('should not detach views in ViewContainers when the parent view is destroyed.', () => {
TestBed.configureTestingModule({declarations: [MyComp, SomeViewport]}); TestBed.configureTestingModule({declarations: [MyComp, SomeViewport]});
const template = const template =
@ -565,7 +567,7 @@ function declareTests(config?: {useJit: boolean}) {
}); });
describe('variables', () => { describe('variables', () => {
fixmeIvy('FW-678: ivy generates different DOM structure for <ng-container>') && modifiedInIvy('Comment node order changed') &&
it('should allow to use variables in a for loop', () => { it('should allow to use variables in a for loop', () => {
const template = const template =
'<ng-template ngFor [ngForOf]="[1]" let-i><child-cmp-no-template #cmp></child-cmp-no-template>{{i}}-{{cmp.ctxProp}}</ng-template>'; '<ng-template ngFor [ngForOf]="[1]" let-i><child-cmp-no-template #cmp></child-cmp-no-template>{{i}}-{{cmp.ctxProp}}</ng-template>';
@ -583,7 +585,8 @@ function declareTests(config?: {useJit: boolean}) {
describe('OnPush components', () => { describe('OnPush components', () => {
fixmeIvy('unknown') && fixmeIvy(
'FW-764: fixture.detectChanges() is not respecting OnPush flag on components in the root template') &&
it('should use ChangeDetectorRef to manually request a check', () => { it('should use ChangeDetectorRef to manually request a check', () => {
TestBed.configureTestingModule({declarations: [MyComp, [[PushCmpWithRef]]]}); TestBed.configureTestingModule({declarations: [MyComp, [[PushCmpWithRef]]]});
const template = '<push-cmp-with-ref #cmp></push-cmp-with-ref>'; const template = '<push-cmp-with-ref #cmp></push-cmp-with-ref>';
@ -604,23 +607,25 @@ function declareTests(config?: {useJit: boolean}) {
expect(cmp.numberOfChecks).toEqual(2); expect(cmp.numberOfChecks).toEqual(2);
}); });
fixmeIvy('unknown') && it('should be checked when its bindings got updated', () => { fixmeIvy(
TestBed.configureTestingModule( 'FW-764: fixture.detectChanges() is not respecting OnPush flag on components in the root template') &&
{declarations: [MyComp, PushCmp, EventCmp], imports: [CommonModule]}); it('should be checked when its bindings got updated', () => {
const template = '<push-cmp [prop]="ctxProp" #cmp></push-cmp>'; TestBed.configureTestingModule(
TestBed.overrideComponent(MyComp, {set: {template}}); {declarations: [MyComp, PushCmp, EventCmp], imports: [CommonModule]});
const fixture = TestBed.createComponent(MyComp); const template = '<push-cmp [prop]="ctxProp" #cmp></push-cmp>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
const cmp = fixture.debugElement.children[0].references !['cmp']; const cmp = fixture.debugElement.children[0].references !['cmp'];
fixture.componentInstance.ctxProp = 'one'; fixture.componentInstance.ctxProp = 'one';
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1); expect(cmp.numberOfChecks).toEqual(1);
fixture.componentInstance.ctxProp = 'two'; fixture.componentInstance.ctxProp = 'two';
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2); expect(cmp.numberOfChecks).toEqual(2);
}); });
if (getDOM().supportsDOMEvents()) { if (getDOM().supportsDOMEvents()) {
fixmeIvy('unknown') && fixmeIvy('unknown') &&
@ -643,43 +648,44 @@ function declareTests(config?: {useJit: boolean}) {
})); }));
} }
fixmeIvy('unknown') && it('should be checked when an event is fired', () => { fixmeIvy('FW-758: OnPush events not marking view dirty when using renderer2') &&
TestBed.configureTestingModule( it('should be checked when an event is fired', () => {
{declarations: [MyComp, PushCmp, EventCmp], imports: [CommonModule]}); TestBed.configureTestingModule(
const template = '<push-cmp [prop]="ctxProp" #cmp></push-cmp>'; {declarations: [MyComp, PushCmp, EventCmp], imports: [CommonModule]});
TestBed.overrideComponent(MyComp, {set: {template}}); const template = '<push-cmp [prop]="ctxProp" #cmp></push-cmp>';
const fixture = TestBed.createComponent(MyComp); TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
const cmpEl = fixture.debugElement.children[0]; const cmpEl = fixture.debugElement.children[0];
const cmp = cmpEl.componentInstance; const cmp = cmpEl.componentInstance;
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(1); expect(cmp.numberOfChecks).toEqual(1);
// regular element // regular element
cmpEl.children[0].triggerEventHandler('click', <Event>{}); cmpEl.children[0].triggerEventHandler('click', <Event>{});
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(2); expect(cmp.numberOfChecks).toEqual(2);
// element inside of an *ngIf // element inside of an *ngIf
cmpEl.children[1].triggerEventHandler('click', <Event>{}); cmpEl.children[1].triggerEventHandler('click', <Event>{});
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(3); expect(cmp.numberOfChecks).toEqual(3);
// element inside a nested component // element inside a nested component
cmpEl.children[2].children[0].triggerEventHandler('click', <Event>{}); cmpEl.children[2].children[0].triggerEventHandler('click', <Event>{});
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(4); expect(cmp.numberOfChecks).toEqual(4);
// host element // host element
cmpEl.triggerEventHandler('click', <Event>{}); cmpEl.triggerEventHandler('click', <Event>{});
fixture.detectChanges(); fixture.detectChanges();
fixture.detectChanges(); fixture.detectChanges();
expect(cmp.numberOfChecks).toEqual(5); expect(cmp.numberOfChecks).toEqual(5);
}); });
it('should not affect updating properties on the component', () => { it('should not affect updating properties on the component', () => {
TestBed.configureTestingModule({declarations: [MyComp, [[PushCmpWithRef]]]}); TestBed.configureTestingModule({declarations: [MyComp, [[PushCmpWithRef]]]});
@ -767,7 +773,8 @@ function declareTests(config?: {useJit: boolean}) {
expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective); expect(childComponent.myHost).toBeAnInstanceOf(SomeDirective);
}); });
fixmeIvy('unknown') && fixmeIvy(
'FW-763: LView tree not properly constructed / destroyed for dynamically inserted components') &&
it('should support events via EventEmitter on regular elements', async(() => { it('should support events via EventEmitter on regular elements', async(() => {
TestBed.configureTestingModule( TestBed.configureTestingModule(
{declarations: [MyComp, DirectiveEmittingEvent, DirectiveListeningEvent]}); {declarations: [MyComp, DirectiveEmittingEvent, DirectiveListeningEvent]});
@ -1490,7 +1497,7 @@ function declareTests(config?: {useJit: boolean}) {
}); });
describe('error handling', () => { describe('error handling', () => {
fixmeIvy('unknown') && fixmeIvy('FW-682: TestBed: tests assert that compilation produces specific error') &&
it('should report a meaningful error when a directive is missing annotation', () => { it('should report a meaningful error when a directive is missing annotation', () => {
TestBed.configureTestingModule( TestBed.configureTestingModule(
{declarations: [MyComp, SomeDirectiveMissingAnnotation]}); {declarations: [MyComp, SomeDirectiveMissingAnnotation]});
@ -1500,7 +1507,7 @@ function declareTests(config?: {useJit: boolean}) {
`Unexpected value '${stringify(SomeDirectiveMissingAnnotation)}' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.`); `Unexpected value '${stringify(SomeDirectiveMissingAnnotation)}' declared by the module 'DynamicTestModule'. Please add a @Pipe/@Directive/@Component annotation.`);
}); });
fixmeIvy('unknown') && fixmeIvy('FW-682: TestBed: tests assert that compilation produces specific error') &&
it('should report a meaningful error when a component is missing view annotation', () => { it('should report a meaningful error when a component is missing view annotation', () => {
TestBed.configureTestingModule({declarations: [MyComp, ComponentWithoutView]}); TestBed.configureTestingModule({declarations: [MyComp, ComponentWithoutView]});
try { try {
@ -1722,15 +1729,17 @@ function declareTests(config?: {useJit: boolean}) {
.toContain('"ng\-reflect\-ng\-if"\: "true"'); .toContain('"ng\-reflect\-ng\-if"\: "true"');
}); });
fixmeIvy('unknown') && it('should indicate when toString() throws', () => { // also affected by FW-587: Inputs with aliases in component decorators don't work
TestBed.configureTestingModule({declarations: [MyComp, MyDir]}); fixmeIvy('FW-664: ng-reflect-* is not supported') &&
const template = '<div my-dir [elprop]="toStringThrow"></div>'; it('should indicate when toString() throws', () => {
TestBed.overrideComponent(MyComp, {set: {template}}); TestBed.configureTestingModule({declarations: [MyComp, MyDir]});
const fixture = TestBed.createComponent(MyComp); const template = '<div my-dir [elprop]="toStringThrow"></div>';
TestBed.overrideComponent(MyComp, {set: {template}});
const fixture = TestBed.createComponent(MyComp);
fixture.detectChanges(); fixture.detectChanges();
expect(getDOM().getInnerHTML(fixture.nativeElement)).toContain('[ERROR]'); expect(getDOM().getInnerHTML(fixture.nativeElement)).toContain('[ERROR]');
}); });
}); });
describe('property decorators', () => { describe('property decorators', () => {

View File

@ -116,7 +116,7 @@ describe('TestBed', () => {
expect(nameInjected).toEqual('World!'); expect(nameInjected).toEqual('World!');
}); });
fixmeIvy('unknown') && it('should give access to the node injector for root node', () => { it('should give access to the node injector for root node', () => {
const hello = TestBed.createComponent(HelloWorld); const hello = TestBed.createComponent(HelloWorld);
hello.detectChanges(); hello.detectChanges();
const injector = hello.debugElement.injector; const injector = hello.debugElement.injector;

View File

@ -117,7 +117,7 @@ import {fixmeIvy} from '@angular/private/testing';
describe('deps', () => { describe('deps', () => {
class Dep {} class Dep {}
fixmeIvy('unknown') && it('should inject deps from the same element', () => { it('should inject deps from the same element', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 2, 'span'), elementDef(0, NodeFlags.None, null, null, 2, 'span'),
directiveDef(1, NodeFlags.None, null, 0, Dep, []), directiveDef(1, NodeFlags.None, null, 0, Dep, []),
@ -127,7 +127,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep instanceof Dep).toBeTruthy(); expect(instance.dep instanceof Dep).toBeTruthy();
}); });
fixmeIvy('unknown') && it('should inject deps from a parent element', () => { it('should inject deps from a parent element', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 3, 'span'), elementDef(0, NodeFlags.None, null, null, 3, 'span'),
directiveDef(1, NodeFlags.None, null, 0, Dep, []), directiveDef(1, NodeFlags.None, null, 0, Dep, []),
@ -167,7 +167,7 @@ import {fixmeIvy} from '@angular/private/testing';
' NullInjectorError: No provider for Dep!'); ' NullInjectorError: No provider for Dep!');
}); });
fixmeIvy('unknown') && it('should inject from a parent element in a parent view', () => { it('should inject from a parent element in a parent view', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef( elementDef(
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null, 0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
@ -192,7 +192,7 @@ import {fixmeIvy} from '@angular/private/testing';
' NullInjectorError: No provider for nonExistingDep!'); ' NullInjectorError: No provider for nonExistingDep!');
}); });
fixmeIvy('unknown') && it('should use null for optional missing dependencies', () => { it('should use null for optional missing dependencies', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'), elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef( directiveDef(
@ -202,7 +202,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep).toBe(null); expect(instance.dep).toBe(null);
}); });
fixmeIvy('unknown') && it('should skip the current element when using SkipSelf', () => { it('should skip the current element when using SkipSelf', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 4, 'span'), elementDef(0, NodeFlags.None, null, null, 4, 'span'),
providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someParentValue', []), providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someParentValue', []),
@ -214,19 +214,18 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep).toBe('someParentValue'); expect(instance.dep).toBe('someParentValue');
}); });
fixmeIvy('unknown') && it('should ask the root injector',
it('should ask the root injector', withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => {
withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => { createAndGetRootNodes(compViewDef([
createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 1, 'span'),
elementDef(0, NodeFlags.None, null, null, 1, 'span'), directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep'])
directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep']) ]));
]));
expect(instance.dep).toBe('rootValue'); expect(instance.dep).toBe('rootValue');
})); }));
describe('builtin tokens', () => { describe('builtin tokens', () => {
fixmeIvy('unknown') && it('should inject ViewContainerRef', () => { it('should inject ViewContainerRef', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.EmbeddedViews, null, null, 1), anchorDef(NodeFlags.EmbeddedViews, null, null, 1),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ViewContainerRef]), directiveDef(1, NodeFlags.None, null, 0, SomeService, [ViewContainerRef]),
@ -235,7 +234,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.createEmbeddedView).toBeTruthy(); expect(instance.dep.createEmbeddedView).toBeTruthy();
}); });
fixmeIvy('unknown') && it('should inject TemplateRef', () => { it('should inject TemplateRef', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
anchorDef(NodeFlags.None, null, null, 1, null, compViewDefFactory([anchorDef( anchorDef(NodeFlags.None, null, null, 1, null, compViewDefFactory([anchorDef(
NodeFlags.None, null, null, 0)])), NodeFlags.None, null, null, 0)])),
@ -245,7 +244,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.createEmbeddedView).toBeTruthy(); expect(instance.dep.createEmbeddedView).toBeTruthy();
}); });
fixmeIvy('unknown') && it('should inject ElementRef', () => { it('should inject ElementRef', () => {
const {view} = createAndGetRootNodes(compViewDef([ const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'), elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ElementRef]), directiveDef(1, NodeFlags.None, null, 0, SomeService, [ElementRef]),
@ -254,7 +253,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.nativeElement).toBe(asElementData(view, 0).renderElement); expect(instance.dep.nativeElement).toBe(asElementData(view, 0).renderElement);
}); });
fixmeIvy('unknown') && it('should inject Injector', () => { it('should inject Injector', () => {
const {view} = createAndGetRootNodes(compViewDef([ const {view} = createAndGetRootNodes(compViewDef([
elementDef(0, NodeFlags.None, null, null, 1, 'span'), elementDef(0, NodeFlags.None, null, null, 1, 'span'),
directiveDef(1, NodeFlags.None, null, 0, SomeService, [Injector]), directiveDef(1, NodeFlags.None, null, 0, SomeService, [Injector]),
@ -263,32 +262,30 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.get(SomeService)).toBe(instance); expect(instance.dep.get(SomeService)).toBe(instance);
}); });
fixmeIvy('unknown') && it('should inject ChangeDetectorRef for non component providers', () => {
it('should inject ChangeDetectorRef for non component providers', () => { const {view} = createAndGetRootNodes(compViewDef([
const {view} = createAndGetRootNodes(compViewDef([ elementDef(0, NodeFlags.None, null, null, 1, 'span'),
elementDef(0, NodeFlags.None, null, null, 1, 'span'), directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef])
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef]) ]));
]));
expect(instance.dep._view).toBe(view); expect(instance.dep._view).toBe(view);
}); });
fixmeIvy('unknown') && it('should inject ChangeDetectorRef for component providers', () => {
it('should inject ChangeDetectorRef for component providers', () => { const {view, rootNodes} = createAndGetRootNodes(compViewDef([
const {view, rootNodes} = createAndGetRootNodes(compViewDef([ elementDef(
elementDef( 0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null, () => compViewDef([
() => compViewDef([ elementDef(0, NodeFlags.None, null, null, 0, 'span'),
elementDef(0, NodeFlags.None, null, null, 0, 'span'), ])),
])), directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]),
directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]), ]));
]));
const compView = asElementData(view, 0).componentView; const compView = asElementData(view, 0).componentView;
expect(instance.dep._view).toBe(compView); expect(instance.dep._view).toBe(compView);
}); });
fixmeIvy('unknown') && it('should inject RendererV1', () => { it('should inject RendererV1', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef( elementDef(
0, NodeFlags.None, null, null, 1, 'span', null, null, null, null, 0, NodeFlags.None, null, null, 1, 'span', null, null, null, null,
@ -299,7 +296,7 @@ import {fixmeIvy} from '@angular/private/testing';
expect(instance.dep.createElement).toBeTruthy(); expect(instance.dep.createElement).toBeTruthy();
}); });
fixmeIvy('unknown') && it('should inject Renderer2', () => { it('should inject Renderer2', () => {
createAndGetRootNodes(compViewDef([ createAndGetRootNodes(compViewDef([
elementDef( elementDef(
0, NodeFlags.None, null, null, 1, 'span', null, null, null, null, 0, NodeFlags.None, null, null, 1, 'span', null, null, null, null,