test: move remaining fixmeIvy to test level (#27354)
Moves all of the remaning `describe`-level fixme instances to the `it` level. PR Close #27354
This commit is contained in:
parent
36e7bf1b7b
commit
23bc8edf24
@ -84,7 +84,7 @@ class NestedAsyncTimeoutComp {
|
||||
}
|
||||
|
||||
{
|
||||
fixmeIvy('unknown') && describe('ComponentFixture', () => {
|
||||
describe('ComponentFixture', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
@ -94,7 +94,7 @@ class NestedAsyncTimeoutComp {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should auto detect changes if autoDetectChanges is called', () => {
|
||||
fixmeIvy('unknown') && it('should auto detect changes if autoDetectChanges is called', () => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AutoDetectComp);
|
||||
expect(componentFixture.ngZone).not.toBeNull();
|
||||
@ -108,181 +108,192 @@ class NestedAsyncTimeoutComp {
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
|
||||
it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
|
||||
withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => {
|
||||
fixmeIvy('unknown') &&
|
||||
it('should auto detect changes if ComponentFixtureAutoDetect is provided as true',
|
||||
withModule({providers: [{provide: ComponentFixtureAutoDetect, useValue: true}]}, () => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AutoDetectComp);
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
const componentFixture = TestBed.createComponent(AutoDetectComp);
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
}));
|
||||
|
||||
it('should signal through whenStable when the fixture is stable (autoDetectChanges)',
|
||||
async(() => {
|
||||
const componentFixture = TestBed.createComponent(AsyncComp);
|
||||
componentFixture.autoDetectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become stable
|
||||
// before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should signal through isStable when the fixture is stable (no autoDetectChanges)',
|
||||
async(() => {
|
||||
const componentFixture = TestBed.createComponent(AsyncComp);
|
||||
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become stable
|
||||
// before checking.
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should wait for macroTask(setTimeout) while checking for whenStable ' +
|
||||
'(autoDetectChanges)',
|
||||
async(() => {
|
||||
const componentFixture = TestBed.createComponent(AsyncTimeoutComp);
|
||||
componentFixture.autoDetectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should wait for macroTask(setTimeout) while checking for whenStable ' +
|
||||
'(no autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AsyncTimeoutComp);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' +
|
||||
'(autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp);
|
||||
|
||||
componentFixture.autoDetectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' +
|
||||
'(no autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should stabilize after async task in change detection (autoDetectChanges)', async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AsyncChangeComp);
|
||||
|
||||
componentFixture.autoDetectChanges();
|
||||
componentFixture.whenStable().then((_) => {
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
|
||||
componentFixture.whenStable().then(
|
||||
(_) => { expect(componentFixture.nativeElement).toHaveText('11'); });
|
||||
});
|
||||
}));
|
||||
|
||||
it('should stabilize after async task in change detection(no autoDetectChanges)', async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AsyncChangeComp);
|
||||
componentFixture.detectChanges();
|
||||
componentFixture.whenStable().then((_) => {
|
||||
// Run detectChanges again so that stabilized value is reflected in the
|
||||
// DOM.
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
componentFixture.detectChanges();
|
||||
|
||||
componentFixture.whenStable().then((_) => {
|
||||
// Run detectChanges again so that stabilized value is reflected in
|
||||
// the DOM.
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should signal through whenStable when the fixture is stable (autoDetectChanges)',
|
||||
async(() => {
|
||||
const componentFixture = TestBed.createComponent(AsyncComp);
|
||||
componentFixture.autoDetectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become stable
|
||||
// before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should signal through isStable when the fixture is stable (no autoDetectChanges)',
|
||||
async(() => {
|
||||
const componentFixture = TestBed.createComponent(AsyncComp);
|
||||
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become stable
|
||||
// before checking.
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should wait for macroTask(setTimeout) while checking for whenStable ' +
|
||||
'(autoDetectChanges)',
|
||||
async(() => {
|
||||
const componentFixture = TestBed.createComponent(AsyncTimeoutComp);
|
||||
componentFixture.autoDetectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should wait for macroTask(setTimeout) while checking for whenStable ' +
|
||||
'(no autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AsyncTimeoutComp);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' +
|
||||
'(autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp);
|
||||
|
||||
componentFixture.autoDetectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should wait for nested macroTasks(setTimeout) while checking for whenStable ' +
|
||||
'(no autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(NestedAsyncTimeoutComp);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
// Component is updated asynchronously. Wait for the fixture to become
|
||||
// stable before checking for new value.
|
||||
expect(componentFixture.isStable()).toBe(false);
|
||||
componentFixture.whenStable().then((waited) => {
|
||||
expect(waited).toBe(true);
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should stabilize after async task in change detection (autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AsyncChangeComp);
|
||||
|
||||
componentFixture.autoDetectChanges();
|
||||
componentFixture.whenStable().then((_) => {
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
|
||||
componentFixture.whenStable().then(
|
||||
(_) => { expect(componentFixture.nativeElement).toHaveText('11'); });
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should stabilize after async task in change detection(no autoDetectChanges)',
|
||||
async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(AsyncChangeComp);
|
||||
componentFixture.detectChanges();
|
||||
componentFixture.whenStable().then((_) => {
|
||||
// Run detectChanges again so that stabilized value is reflected in the
|
||||
// DOM.
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('1');
|
||||
|
||||
const element = componentFixture.debugElement.children[0];
|
||||
dispatchEvent(element.nativeElement, 'click');
|
||||
componentFixture.detectChanges();
|
||||
|
||||
componentFixture.whenStable().then((_) => {
|
||||
// Run detectChanges again so that stabilized value is reflected in
|
||||
// the DOM.
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('11');
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
describe('No NgZone', () => {
|
||||
beforeEach(() => {
|
||||
@ -290,7 +301,7 @@ class NestedAsyncTimeoutComp {
|
||||
{providers: [{provide: ComponentFixtureNoNgZone, useValue: true}]});
|
||||
});
|
||||
|
||||
it('calling autoDetectChanges raises an error', () => {
|
||||
fixmeIvy('unknown') && it('calling autoDetectChanges raises an error', () => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(SimpleComp);
|
||||
expect(() => {
|
||||
@ -298,27 +309,28 @@ class NestedAsyncTimeoutComp {
|
||||
}).toThrowError(/Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set/);
|
||||
});
|
||||
|
||||
it('should instantiate a component with valid DOM', async(() => {
|
||||
fixmeIvy('unknown') &&
|
||||
it('should instantiate a component with valid DOM', async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(SimpleComp);
|
||||
const componentFixture = TestBed.createComponent(SimpleComp);
|
||||
|
||||
expect(componentFixture.ngZone).toBeNull();
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('Original Simple');
|
||||
}));
|
||||
expect(componentFixture.ngZone).toBeNull();
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('Original Simple');
|
||||
}));
|
||||
|
||||
it('should allow changing members of the component', async(() => {
|
||||
fixmeIvy('unknown') && it('should allow changing members of the component', async(() => {
|
||||
|
||||
const componentFixture = TestBed.createComponent(MyIfComp);
|
||||
const componentFixture = TestBed.createComponent(MyIfComp);
|
||||
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('MyIf()');
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('MyIf()');
|
||||
|
||||
componentFixture.componentInstance.showMore = true;
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('MyIf(More)');
|
||||
componentFixture.componentInstance.showMore = true;
|
||||
componentFixture.detectChanges();
|
||||
expect(componentFixture.nativeElement).toHaveText('MyIf(More)');
|
||||
|
||||
}));
|
||||
}));
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -169,7 +169,7 @@ class TestApp {
|
||||
}
|
||||
|
||||
{
|
||||
fixmeIvy('unknown') && describe('debug element', () => {
|
||||
describe('debug element', () => {
|
||||
let fixture: ComponentFixture<any>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
@ -192,13 +192,13 @@ class TestApp {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should list all child nodes', () => {
|
||||
fixmeIvy('unknown') && it('should list all child nodes', () => {
|
||||
fixture = TestBed.createComponent(ParentComp);
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.childNodes.length).toEqual(3);
|
||||
});
|
||||
|
||||
it('should list all component child elements', () => {
|
||||
fixmeIvy('unknown') && it('should list all component child elements', () => {
|
||||
fixture = TestBed.createComponent(ParentComp);
|
||||
fixture.detectChanges();
|
||||
const childEls = fixture.debugElement.children;
|
||||
@ -225,7 +225,7 @@ class TestApp {
|
||||
expect(getDOM().hasClass(childNested[0].nativeElement, 'childnested')).toBe(true);
|
||||
});
|
||||
|
||||
it('should list conditional component child elements', () => {
|
||||
fixmeIvy('unknown') && it('should list conditional component child elements', () => {
|
||||
fixture = TestBed.createComponent(ConditionalParentComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -246,7 +246,7 @@ class TestApp {
|
||||
expect(conditionalContentComp.children.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should list child elements within viewports', () => {
|
||||
fixmeIvy('unknown') && it('should list child elements within viewports', () => {
|
||||
fixture = TestBed.createComponent(UsingFor);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -259,7 +259,7 @@ class TestApp {
|
||||
expect(list.children.length).toEqual(3);
|
||||
});
|
||||
|
||||
it('should list element attributes', () => {
|
||||
fixmeIvy('unknown') && it('should list element attributes', () => {
|
||||
fixture = TestBed.createComponent(TestApp);
|
||||
fixture.detectChanges();
|
||||
const bankElem = fixture.debugElement.children[0];
|
||||
@ -268,7 +268,7 @@ class TestApp {
|
||||
expect(bankElem.attributes['account']).toEqual('4747');
|
||||
});
|
||||
|
||||
it('should list element classes', () => {
|
||||
fixmeIvy('unknown') && it('should list element classes', () => {
|
||||
fixture = TestBed.createComponent(TestApp);
|
||||
fixture.detectChanges();
|
||||
const bankElem = fixture.debugElement.children[0];
|
||||
@ -277,7 +277,7 @@ class TestApp {
|
||||
expect(bankElem.classes['open']).toBe(false);
|
||||
});
|
||||
|
||||
it('should list element styles', () => {
|
||||
fixmeIvy('unknown') && it('should list element styles', () => {
|
||||
fixture = TestBed.createComponent(TestApp);
|
||||
fixture.detectChanges();
|
||||
const bankElem = fixture.debugElement.children[0];
|
||||
@ -286,7 +286,7 @@ class TestApp {
|
||||
expect(bankElem.styles['color']).toEqual('red');
|
||||
});
|
||||
|
||||
it('should query child elements by css', () => {
|
||||
fixmeIvy('unknown') && it('should query child elements by css', () => {
|
||||
fixture = TestBed.createComponent(ParentComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -296,7 +296,7 @@ class TestApp {
|
||||
expect(getDOM().hasClass(childTestEls[0].nativeElement, 'child-comp-class')).toBe(true);
|
||||
});
|
||||
|
||||
it('should query child elements by directive', () => {
|
||||
fixmeIvy('unknown') && it('should query child elements by directive', () => {
|
||||
fixture = TestBed.createComponent(ParentComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -309,21 +309,21 @@ class TestApp {
|
||||
expect(getDOM().hasClass(childTestEls[3].nativeElement, 'childnested')).toBe(true);
|
||||
});
|
||||
|
||||
it('should list providerTokens', () => {
|
||||
fixmeIvy('unknown') && it('should list providerTokens', () => {
|
||||
fixture = TestBed.createComponent(ParentComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.debugElement.providerTokens).toContain(Logger);
|
||||
});
|
||||
|
||||
it('should list locals', () => {
|
||||
fixmeIvy('unknown') && it('should list locals', () => {
|
||||
fixture = TestBed.createComponent(LocalsComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.debugElement.children[0].references !['alice']).toBeAnInstanceOf(MyDir);
|
||||
});
|
||||
|
||||
it('should allow injecting from the element injector', () => {
|
||||
fixmeIvy('unknown') && it('should allow injecting from the element injector', () => {
|
||||
fixture = TestBed.createComponent(ParentComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -332,7 +332,7 @@ class TestApp {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should list event listeners', () => {
|
||||
fixmeIvy('unknown') && it('should list event listeners', () => {
|
||||
fixture = TestBed.createComponent(EventsComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -341,7 +341,7 @@ class TestApp {
|
||||
|
||||
});
|
||||
|
||||
it('should trigger event handlers', () => {
|
||||
fixmeIvy('unknown') && it('should trigger event handlers', () => {
|
||||
fixture = TestBed.createComponent(EventsComp);
|
||||
fixture.detectChanges();
|
||||
|
||||
|
@ -13,7 +13,7 @@ import {Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {fixmeIvy} from '@angular/private/testing';
|
||||
|
||||
{
|
||||
fixmeIvy('unknown') && describe('directive lifecycle integration spec', () => {
|
||||
describe('directive lifecycle integration spec', () => {
|
||||
let log: Log;
|
||||
|
||||
beforeEach(() => {
|
||||
@ -31,22 +31,23 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
|
||||
beforeEach(inject([Log], (_log: any) => { log = _log; }));
|
||||
|
||||
it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked',
|
||||
() => {
|
||||
const fixture = TestBed.createComponent(MyComp5);
|
||||
fixture.detectChanges();
|
||||
fixmeIvy('unknown') &&
|
||||
it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked',
|
||||
() => {
|
||||
const fixture = TestBed.createComponent(MyComp5);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(log.result())
|
||||
.toEqual(
|
||||
'ngOnChanges; ngOnInit; ngDoCheck; ngAfterContentInit; ngAfterContentChecked; child_ngDoCheck; ' +
|
||||
'ngAfterViewInit; ngAfterViewChecked');
|
||||
expect(log.result())
|
||||
.toEqual(
|
||||
'ngOnChanges; ngOnInit; ngDoCheck; ngAfterContentInit; ngAfterContentChecked; child_ngDoCheck; ' +
|
||||
'ngAfterViewInit; ngAfterViewChecked');
|
||||
|
||||
log.clear();
|
||||
fixture.detectChanges();
|
||||
log.clear();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(log.result())
|
||||
.toEqual('ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked');
|
||||
});
|
||||
expect(log.result())
|
||||
.toEqual('ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -18,32 +18,33 @@ const resolvedPromise = Promise.resolve(null);
|
||||
const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'];
|
||||
|
||||
{
|
||||
fixmeIvy('unknown') && describe('fake async', () => {
|
||||
it('should run synchronous code', () => {
|
||||
describe('fake async', () => {
|
||||
fixmeIvy('unknown') && it('should run synchronous code', () => {
|
||||
let ran = false;
|
||||
fakeAsync(() => { ran = true; })();
|
||||
|
||||
expect(ran).toEqual(true);
|
||||
});
|
||||
|
||||
it('should pass arguments to the wrapped function', () => {
|
||||
fixmeIvy('unknown') && it('should pass arguments to the wrapped function', () => {
|
||||
fakeAsync((foo: any /** TODO #9100 */, bar: any /** TODO #9100 */) => {
|
||||
expect(foo).toEqual('foo');
|
||||
expect(bar).toEqual('bar');
|
||||
})('foo', 'bar');
|
||||
});
|
||||
|
||||
it('should work with inject()', fakeAsync(inject([Parser], (parser: any /** TODO #9100 */) => {
|
||||
expect(parser).toBeAnInstanceOf(Parser);
|
||||
})));
|
||||
fixmeIvy('unknown') && it('should work with inject()',
|
||||
fakeAsync(inject([Parser], (parser: any /** TODO #9100 */) => {
|
||||
expect(parser).toBeAnInstanceOf(Parser);
|
||||
})));
|
||||
|
||||
it('should throw on nested calls', () => {
|
||||
fixmeIvy('unknown') && it('should throw on nested calls', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => { fakeAsync((): any /** TODO #9100 */ => null)(); })();
|
||||
}).toThrowError('fakeAsync() calls can not be nested');
|
||||
});
|
||||
|
||||
it('should flush microtasks before returning', () => {
|
||||
fixmeIvy('unknown') && it('should flush microtasks before returning', () => {
|
||||
let thenRan = false;
|
||||
|
||||
fakeAsync(() => { resolvedPromise.then(_ => { thenRan = true; }); })();
|
||||
@ -52,275 +53,280 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
});
|
||||
|
||||
|
||||
it('should propagate the return value',
|
||||
() => { expect(fakeAsync(() => 'foo')()).toEqual('foo'); });
|
||||
fixmeIvy('unknown') && it('should propagate the return value',
|
||||
() => { expect(fakeAsync(() => 'foo')()).toEqual('foo'); });
|
||||
|
||||
describe('Promise', () => {
|
||||
it('should run asynchronous code', fakeAsync(() => {
|
||||
let thenRan = false;
|
||||
resolvedPromise.then((_) => { thenRan = true; });
|
||||
fixmeIvy('unknown') && it('should run asynchronous code', fakeAsync(() => {
|
||||
let thenRan = false;
|
||||
resolvedPromise.then((_) => { thenRan = true; });
|
||||
|
||||
expect(thenRan).toEqual(false);
|
||||
expect(thenRan).toEqual(false);
|
||||
|
||||
flushMicrotasks();
|
||||
expect(thenRan).toEqual(true);
|
||||
}));
|
||||
flushMicrotasks();
|
||||
expect(thenRan).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should run chained thens', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
fixmeIvy('unknown') && it('should run chained thens', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
|
||||
resolvedPromise.then((_) => log.add(1)).then((_) => log.add(2));
|
||||
resolvedPromise.then((_) => log.add(1)).then((_) => log.add(2));
|
||||
|
||||
expect(log.result()).toEqual('');
|
||||
expect(log.result()).toEqual('');
|
||||
|
||||
flushMicrotasks();
|
||||
expect(log.result()).toEqual('1; 2');
|
||||
}));
|
||||
flushMicrotasks();
|
||||
expect(log.result()).toEqual('1; 2');
|
||||
}));
|
||||
|
||||
it('should run Promise created in Promise', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
fixmeIvy('unknown') && it('should run Promise created in Promise', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
|
||||
resolvedPromise.then((_) => {
|
||||
log.add(1);
|
||||
resolvedPromise.then((_) => log.add(2));
|
||||
});
|
||||
resolvedPromise.then((_) => {
|
||||
log.add(1);
|
||||
resolvedPromise.then((_) => log.add(2));
|
||||
});
|
||||
|
||||
expect(log.result()).toEqual('');
|
||||
expect(log.result()).toEqual('');
|
||||
|
||||
flushMicrotasks();
|
||||
expect(log.result()).toEqual('1; 2');
|
||||
}));
|
||||
flushMicrotasks();
|
||||
expect(log.result()).toEqual('1; 2');
|
||||
}));
|
||||
|
||||
it('should complain if the test throws an exception during async calls', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => {
|
||||
resolvedPromise.then((_) => { throw new Error('async'); });
|
||||
flushMicrotasks();
|
||||
})();
|
||||
}).toThrowError(/Uncaught \(in promise\): Error: async/);
|
||||
});
|
||||
fixmeIvy('unknown') &&
|
||||
it('should complain if the test throws an exception during async calls', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => {
|
||||
resolvedPromise.then((_) => { throw new Error('async'); });
|
||||
flushMicrotasks();
|
||||
})();
|
||||
}).toThrowError(/Uncaught \(in promise\): Error: async/);
|
||||
});
|
||||
|
||||
it('should complain if a test throws an exception', () => {
|
||||
fixmeIvy('unknown') && it('should complain if a test throws an exception', () => {
|
||||
expect(() => { fakeAsync(() => { throw new Error('sync'); })(); }).toThrowError('sync');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('timers', () => {
|
||||
it('should run queued zero duration timer on zero tick', fakeAsync(() => {
|
||||
let ran = false;
|
||||
setTimeout(() => { ran = true; }, 0);
|
||||
fixmeIvy('unknown') &&
|
||||
it('should run queued zero duration timer on zero tick', fakeAsync(() => {
|
||||
let ran = false;
|
||||
setTimeout(() => { ran = true; }, 0);
|
||||
|
||||
expect(ran).toEqual(false);
|
||||
expect(ran).toEqual(false);
|
||||
|
||||
tick();
|
||||
expect(ran).toEqual(true);
|
||||
}));
|
||||
tick();
|
||||
expect(ran).toEqual(true);
|
||||
}));
|
||||
|
||||
|
||||
it('should run queued timer after sufficient clock ticks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
setTimeout(() => { ran = true; }, 10);
|
||||
fixmeIvy('unknown') &&
|
||||
it('should run queued timer after sufficient clock ticks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
setTimeout(() => { ran = true; }, 10);
|
||||
|
||||
tick(6);
|
||||
expect(ran).toEqual(false);
|
||||
tick(6);
|
||||
expect(ran).toEqual(false);
|
||||
|
||||
tick(6);
|
||||
expect(ran).toEqual(true);
|
||||
}));
|
||||
tick(6);
|
||||
expect(ran).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should run queued timer only once', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
setTimeout(() => { cycles++; }, 10);
|
||||
fixmeIvy('unknown') && it('should run queued timer only once', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
setTimeout(() => { cycles++; }, 10);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
}));
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
}));
|
||||
|
||||
it('should not run cancelled timer', fakeAsync(() => {
|
||||
let ran = false;
|
||||
const id = setTimeout(() => { ran = true; }, 10);
|
||||
clearTimeout(id);
|
||||
fixmeIvy('unknown') && it('should not run cancelled timer', fakeAsync(() => {
|
||||
let ran = false;
|
||||
const id = setTimeout(() => { ran = true; }, 10);
|
||||
clearTimeout(id);
|
||||
|
||||
tick(10);
|
||||
expect(ran).toEqual(false);
|
||||
}));
|
||||
tick(10);
|
||||
expect(ran).toEqual(false);
|
||||
}));
|
||||
|
||||
it('should throw an error on dangling timers', () => {
|
||||
fixmeIvy('unknown') && it('should throw an error on dangling timers', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => { setTimeout(() => {}, 10); })();
|
||||
}).toThrowError('1 timer(s) still in the queue.');
|
||||
});
|
||||
|
||||
it('should throw an error on dangling periodic timers', () => {
|
||||
fixmeIvy('unknown') && it('should throw an error on dangling periodic timers', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => { setInterval(() => {}, 10); })();
|
||||
}).toThrowError('1 periodic timer(s) still in the queue.');
|
||||
});
|
||||
|
||||
it('should run periodic timers', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
const id = setInterval(() => { cycles++; }, 10);
|
||||
fixmeIvy('unknown') && it('should run periodic timers', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
const id = setInterval(() => { cycles++; }, 10);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(2);
|
||||
tick(10);
|
||||
expect(cycles).toEqual(2);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(3);
|
||||
clearInterval(id);
|
||||
}));
|
||||
tick(10);
|
||||
expect(cycles).toEqual(3);
|
||||
clearInterval(id);
|
||||
}));
|
||||
|
||||
it('should not run cancelled periodic timer', fakeAsync(() => {
|
||||
let ran = false;
|
||||
const id = setInterval(() => { ran = true; }, 10);
|
||||
clearInterval(id);
|
||||
fixmeIvy('unknown') && it('should not run cancelled periodic timer', fakeAsync(() => {
|
||||
let ran = false;
|
||||
const id = setInterval(() => { ran = true; }, 10);
|
||||
clearInterval(id);
|
||||
|
||||
tick(10);
|
||||
expect(ran).toEqual(false);
|
||||
}));
|
||||
tick(10);
|
||||
expect(ran).toEqual(false);
|
||||
}));
|
||||
|
||||
it('should be able to cancel periodic timers from a callback', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
let id: any /** TODO #9100 */;
|
||||
fixmeIvy('unknown') &&
|
||||
it('should be able to cancel periodic timers from a callback', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
let id: any /** TODO #9100 */;
|
||||
|
||||
id = setInterval(() => {
|
||||
cycles++;
|
||||
clearInterval(id);
|
||||
}, 10);
|
||||
id = setInterval(() => {
|
||||
cycles++;
|
||||
clearInterval(id);
|
||||
}, 10);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
}));
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
}));
|
||||
|
||||
it('should clear periodic timers', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
const id = setInterval(() => { cycles++; }, 10);
|
||||
fixmeIvy('unknown') && it('should clear periodic timers', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
const id = setInterval(() => { cycles++; }, 10);
|
||||
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
tick(10);
|
||||
expect(cycles).toEqual(1);
|
||||
|
||||
discardPeriodicTasks();
|
||||
discardPeriodicTasks();
|
||||
|
||||
// Tick once to clear out the timer which already started.
|
||||
tick(10);
|
||||
expect(cycles).toEqual(2);
|
||||
// Tick once to clear out the timer which already started.
|
||||
tick(10);
|
||||
expect(cycles).toEqual(2);
|
||||
|
||||
tick(10);
|
||||
// Nothing should change
|
||||
expect(cycles).toEqual(2);
|
||||
}));
|
||||
tick(10);
|
||||
// Nothing should change
|
||||
expect(cycles).toEqual(2);
|
||||
}));
|
||||
|
||||
it('should process microtasks before timers', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
fixmeIvy('unknown') && it('should process microtasks before timers', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
|
||||
resolvedPromise.then((_) => log.add('microtask'));
|
||||
resolvedPromise.then((_) => log.add('microtask'));
|
||||
|
||||
setTimeout(() => log.add('timer'), 9);
|
||||
setTimeout(() => log.add('timer'), 9);
|
||||
|
||||
const id = setInterval(() => log.add('periodic timer'), 10);
|
||||
const id = setInterval(() => log.add('periodic timer'), 10);
|
||||
|
||||
expect(log.result()).toEqual('');
|
||||
expect(log.result()).toEqual('');
|
||||
|
||||
tick(10);
|
||||
expect(log.result()).toEqual('microtask; timer; periodic timer');
|
||||
clearInterval(id);
|
||||
}));
|
||||
tick(10);
|
||||
expect(log.result()).toEqual('microtask; timer; periodic timer');
|
||||
clearInterval(id);
|
||||
}));
|
||||
|
||||
it('should process micro-tasks created in timers before next timers', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
fixmeIvy('unknown') &&
|
||||
it('should process micro-tasks created in timers before next timers', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
|
||||
resolvedPromise.then((_) => log.add('microtask'));
|
||||
resolvedPromise.then((_) => log.add('microtask'));
|
||||
|
||||
setTimeout(() => {
|
||||
log.add('timer');
|
||||
resolvedPromise.then((_) => log.add('t microtask'));
|
||||
}, 9);
|
||||
setTimeout(() => {
|
||||
log.add('timer');
|
||||
resolvedPromise.then((_) => log.add('t microtask'));
|
||||
}, 9);
|
||||
|
||||
const id = setInterval(() => {
|
||||
log.add('periodic timer');
|
||||
resolvedPromise.then((_) => log.add('pt microtask'));
|
||||
}, 10);
|
||||
const id = setInterval(() => {
|
||||
log.add('periodic timer');
|
||||
resolvedPromise.then((_) => log.add('pt microtask'));
|
||||
}, 10);
|
||||
|
||||
tick(10);
|
||||
expect(log.result())
|
||||
.toEqual('microtask; timer; t microtask; periodic timer; pt microtask');
|
||||
tick(10);
|
||||
expect(log.result())
|
||||
.toEqual('microtask; timer; t microtask; periodic timer; pt microtask');
|
||||
|
||||
tick(10);
|
||||
expect(log.result())
|
||||
.toEqual(
|
||||
'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask');
|
||||
clearInterval(id);
|
||||
}));
|
||||
tick(10);
|
||||
expect(log.result())
|
||||
.toEqual(
|
||||
'microtask; timer; t microtask; periodic timer; pt microtask; periodic timer; pt microtask');
|
||||
clearInterval(id);
|
||||
}));
|
||||
|
||||
it('should flush tasks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
setTimeout(() => { ran = true; }, 10);
|
||||
fixmeIvy('unknown') && it('should flush tasks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
setTimeout(() => { ran = true; }, 10);
|
||||
|
||||
flush();
|
||||
expect(ran).toEqual(true);
|
||||
}));
|
||||
flush();
|
||||
expect(ran).toEqual(true);
|
||||
}));
|
||||
|
||||
it('should flush multiple tasks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
let ran2 = false;
|
||||
setTimeout(() => { ran = true; }, 10);
|
||||
setTimeout(() => { ran2 = true; }, 30);
|
||||
fixmeIvy('unknown') && it('should flush multiple tasks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
let ran2 = false;
|
||||
setTimeout(() => { ran = true; }, 10);
|
||||
setTimeout(() => { ran2 = true; }, 30);
|
||||
|
||||
let elapsed = flush();
|
||||
let elapsed = flush();
|
||||
|
||||
expect(ran).toEqual(true);
|
||||
expect(ran2).toEqual(true);
|
||||
expect(elapsed).toEqual(30);
|
||||
}));
|
||||
expect(ran).toEqual(true);
|
||||
expect(ran2).toEqual(true);
|
||||
expect(elapsed).toEqual(30);
|
||||
}));
|
||||
|
||||
it('should move periodic tasks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
let count = 0;
|
||||
setInterval(() => { count++; }, 10);
|
||||
setTimeout(() => { ran = true; }, 35);
|
||||
fixmeIvy('unknown') && it('should move periodic tasks', fakeAsync(() => {
|
||||
let ran = false;
|
||||
let count = 0;
|
||||
setInterval(() => { count++; }, 10);
|
||||
setTimeout(() => { ran = true; }, 35);
|
||||
|
||||
let elapsed = flush();
|
||||
let elapsed = flush();
|
||||
|
||||
expect(count).toEqual(3);
|
||||
expect(ran).toEqual(true);
|
||||
expect(elapsed).toEqual(35);
|
||||
expect(count).toEqual(3);
|
||||
expect(ran).toEqual(true);
|
||||
expect(elapsed).toEqual(35);
|
||||
|
||||
discardPeriodicTasks();
|
||||
}));
|
||||
discardPeriodicTasks();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('outside of the fakeAsync zone', () => {
|
||||
it('calling flushMicrotasks should throw', () => {
|
||||
fixmeIvy('unknown') && it('calling flushMicrotasks should throw', () => {
|
||||
expect(() => {
|
||||
flushMicrotasks();
|
||||
}).toThrowError('The code should be running in the fakeAsync zone to call this function');
|
||||
});
|
||||
|
||||
it('calling tick should throw', () => {
|
||||
fixmeIvy('unknown') && it('calling tick should throw', () => {
|
||||
expect(() => {
|
||||
tick();
|
||||
}).toThrowError('The code should be running in the fakeAsync zone to call this function');
|
||||
});
|
||||
|
||||
it('calling flush should throw', () => {
|
||||
fixmeIvy('unknown') && it('calling flush should throw', () => {
|
||||
expect(() => {
|
||||
flush();
|
||||
}).toThrowError('The code should be running in the fakeAsync zone to call this function');
|
||||
});
|
||||
|
||||
it('calling discardPeriodicTasks should throw', () => {
|
||||
fixmeIvy('unknown') && it('calling discardPeriodicTasks should throw', () => {
|
||||
expect(() => {
|
||||
discardPeriodicTasks();
|
||||
}).toThrowError('The code should be running in the fakeAsync zone to call this function');
|
||||
@ -332,10 +338,10 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
let zoneInTest1: Zone;
|
||||
beforeEach(fakeAsync(() => { zoneInBeforeEach = Zone.current; }));
|
||||
|
||||
it('should use the same zone as in beforeEach', fakeAsync(() => {
|
||||
zoneInTest1 = Zone.current;
|
||||
expect(zoneInTest1).toBe(zoneInBeforeEach);
|
||||
}));
|
||||
fixmeIvy('unknown') && it('should use the same zone as in beforeEach', fakeAsync(() => {
|
||||
zoneInTest1 = Zone.current;
|
||||
expect(zoneInTest1).toBe(zoneInBeforeEach);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
@ -344,19 +350,21 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
|
||||
afterEach(() => { ProxyZoneSpec.assertPresent(); });
|
||||
|
||||
it('should allow fakeAsync zone to retroactively set a zoneSpec outside of fakeAsync', () => {
|
||||
ProxyZoneSpec.assertPresent();
|
||||
let state: string = 'not run';
|
||||
const testZone = Zone.current.fork({name: 'test-zone'});
|
||||
(fakeAsync(() => {
|
||||
testZone.run(() => {
|
||||
Promise.resolve('works').then((v) => state = v);
|
||||
expect(state).toEqual('not run');
|
||||
flushMicrotasks();
|
||||
expect(state).toEqual('works');
|
||||
});
|
||||
}))();
|
||||
expect(state).toEqual('works');
|
||||
});
|
||||
fixmeIvy('unknown') &&
|
||||
it('should allow fakeAsync zone to retroactively set a zoneSpec outside of fakeAsync',
|
||||
() => {
|
||||
ProxyZoneSpec.assertPresent();
|
||||
let state: string = 'not run';
|
||||
const testZone = Zone.current.fork({name: 'test-zone'});
|
||||
(fakeAsync(() => {
|
||||
testZone.run(() => {
|
||||
Promise.resolve('works').then((v) => state = v);
|
||||
expect(state).toEqual('not run');
|
||||
flushMicrotasks();
|
||||
expect(state).toEqual('works');
|
||||
});
|
||||
}))();
|
||||
expect(state).toEqual('works');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -13,15 +13,17 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
import {fixmeIvy} from '@angular/private/testing';
|
||||
|
||||
{
|
||||
fixmeIvy('unknown') && describe('forwardRef integration', function() {
|
||||
describe('forwardRef integration', function() {
|
||||
beforeEach(() => { TestBed.configureTestingModule({imports: [Module], declarations: [App]}); });
|
||||
|
||||
it('should instantiate components which are declared using forwardRef', () => {
|
||||
const a = TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}).createComponent(App);
|
||||
a.detectChanges();
|
||||
expect(asNativeElements(a.debugElement.children)).toHaveText('frame(lock)');
|
||||
expect(TestBed.get(ModuleFrame)).toBeDefined();
|
||||
});
|
||||
fixmeIvy('unknown') &&
|
||||
it('should instantiate components which are declared using forwardRef', () => {
|
||||
const a =
|
||||
TestBed.configureTestingModule({schemas: [NO_ERRORS_SCHEMA]}).createComponent(App);
|
||||
a.detectChanges();
|
||||
expect(asNativeElements(a.debugElement.children)).toHaveText('frame(lock)');
|
||||
expect(TestBed.get(ModuleFrame)).toBeDefined();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
|
||||
{
|
||||
// ivy fix in https://github.com/angular/angular/pull/26871
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') && describe('Jit Summaries', () => {
|
||||
describe('Jit Summaries', () => {
|
||||
let instances: Map<any, Base>;
|
||||
let summaries: () => any[];
|
||||
|
||||
@ -138,146 +138,160 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
|
||||
afterEach(() => { resetTestEnvironmentWithSummaries(); });
|
||||
|
||||
it('should use directive metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should use directive metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
@Component({template: '<div someDir></div>'})
|
||||
class TestComp {
|
||||
}
|
||||
@Component({template: '<div someDir></div>'})
|
||||
class TestComp {
|
||||
}
|
||||
|
||||
TestBed
|
||||
.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomeDirective]})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
});
|
||||
TestBed
|
||||
.configureTestingModule(
|
||||
{providers: [SomeDep], declarations: [TestComp, SomeDirective]})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
});
|
||||
|
||||
it('should use pipe metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should use pipe metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
@Component({template: '{{1 | somePipe}}'})
|
||||
class TestComp {
|
||||
}
|
||||
@Component({template: '{{1 | somePipe}}'})
|
||||
class TestComp {
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomePipe]})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomePipe);
|
||||
});
|
||||
TestBed.configureTestingModule({providers: [SomeDep], declarations: [TestComp, SomePipe]})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomePipe);
|
||||
});
|
||||
|
||||
it('should use Service metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should use Service metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SomeService, SomeDep],
|
||||
});
|
||||
TestBed.get(SomeService);
|
||||
expectInstanceCreated(SomeService);
|
||||
});
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SomeService, SomeDep],
|
||||
});
|
||||
TestBed.get(SomeService);
|
||||
expectInstanceCreated(SomeService);
|
||||
});
|
||||
|
||||
it('should use NgModule metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should use NgModule metadata from summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
TestBed
|
||||
.configureTestingModule(
|
||||
{providers: [SomeDep], declarations: [TestComp3], imports: [SomeModule]})
|
||||
.createComponent(TestComp3);
|
||||
TestBed
|
||||
.configureTestingModule(
|
||||
{providers: [SomeDep], declarations: [TestComp3], imports: [SomeModule]})
|
||||
.createComponent(TestComp3);
|
||||
|
||||
expectInstanceCreated(SomeModule);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
expectInstanceCreated(SomePipe);
|
||||
expectInstanceCreated(SomeService);
|
||||
});
|
||||
expectInstanceCreated(SomeModule);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
expectInstanceCreated(SomePipe);
|
||||
expectInstanceCreated(SomeService);
|
||||
});
|
||||
|
||||
it('should allow to create private components from imported NgModule summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should allow to create private components from imported NgModule summaries', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent(SomePrivateComponent);
|
||||
expectInstanceCreated(SomePrivateComponent);
|
||||
});
|
||||
TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent(SomePrivateComponent);
|
||||
expectInstanceCreated(SomePrivateComponent);
|
||||
});
|
||||
|
||||
it('should throw when trying to mock a type with a summary', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should throw when trying to mock a type with a summary', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
TestBed.resetTestingModule();
|
||||
expect(() => TestBed.overrideComponent(SomePrivateComponent, {add: {}}).compileComponents())
|
||||
.toThrowError(
|
||||
'SomePrivateComponent was AOT compiled, so its metadata cannot be changed.');
|
||||
TestBed.resetTestingModule();
|
||||
expect(() => TestBed.overrideDirective(SomeDirective, {add: {}}).compileComponents())
|
||||
.toThrowError('SomeDirective was AOT compiled, so its metadata cannot be changed.');
|
||||
TestBed.resetTestingModule();
|
||||
expect(() => TestBed.overridePipe(SomePipe, {add: {name: 'test'}}).compileComponents())
|
||||
.toThrowError('SomePipe was AOT compiled, so its metadata cannot be changed.');
|
||||
TestBed.resetTestingModule();
|
||||
expect(() => TestBed.overrideModule(SomeModule, {add: {}}).compileComponents())
|
||||
.toThrowError('SomeModule was AOT compiled, so its metadata cannot be changed.');
|
||||
});
|
||||
TestBed.resetTestingModule();
|
||||
expect(
|
||||
() => TestBed.overrideComponent(SomePrivateComponent, {add: {}}).compileComponents())
|
||||
.toThrowError(
|
||||
'SomePrivateComponent was AOT compiled, so its metadata cannot be changed.');
|
||||
TestBed.resetTestingModule();
|
||||
expect(() => TestBed.overrideDirective(SomeDirective, {add: {}}).compileComponents())
|
||||
.toThrowError('SomeDirective was AOT compiled, so its metadata cannot be changed.');
|
||||
TestBed.resetTestingModule();
|
||||
expect(() => TestBed.overridePipe(SomePipe, {add: {name: 'test'}}).compileComponents())
|
||||
.toThrowError('SomePipe was AOT compiled, so its metadata cannot be changed.');
|
||||
TestBed.resetTestingModule();
|
||||
expect(() => TestBed.overrideModule(SomeModule, {add: {}}).compileComponents())
|
||||
.toThrowError('SomeModule was AOT compiled, so its metadata cannot be changed.');
|
||||
});
|
||||
|
||||
it('should return stack trace and component data on resetTestingModule when error is thrown',
|
||||
() => {
|
||||
resetTestEnvironmentWithSummaries();
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should return stack trace and component data on resetTestingModule when error is thrown',
|
||||
() => {
|
||||
resetTestEnvironmentWithSummaries();
|
||||
|
||||
const fixture = TestBed.configureTestingModule({declarations: [TestCompErrorOnDestroy]})
|
||||
.createComponent<TestCompErrorOnDestroy>(TestCompErrorOnDestroy);
|
||||
const fixture =
|
||||
TestBed.configureTestingModule({declarations: [TestCompErrorOnDestroy]})
|
||||
.createComponent<TestCompErrorOnDestroy>(TestCompErrorOnDestroy);
|
||||
|
||||
const expectedError = 'Error from ngOnDestroy';
|
||||
const expectedError = 'Error from ngOnDestroy';
|
||||
|
||||
const component: TestCompErrorOnDestroy = fixture.componentInstance;
|
||||
const component: TestCompErrorOnDestroy = fixture.componentInstance;
|
||||
|
||||
spyOn(console, 'error');
|
||||
spyOn(component, 'ngOnDestroy').and.throwError(expectedError);
|
||||
spyOn(console, 'error');
|
||||
spyOn(component, 'ngOnDestroy').and.throwError(expectedError);
|
||||
|
||||
const expectedObject = {
|
||||
stacktrace: new Error(expectedError),
|
||||
component,
|
||||
};
|
||||
const expectedObject = {
|
||||
stacktrace: new Error(expectedError),
|
||||
component,
|
||||
};
|
||||
|
||||
TestBed.resetTestingModule();
|
||||
TestBed.resetTestingModule();
|
||||
|
||||
expect(console.error)
|
||||
.toHaveBeenCalledWith('Error during cleanup of component', expectedObject);
|
||||
});
|
||||
expect(console.error)
|
||||
.toHaveBeenCalledWith('Error during cleanup of component', expectedObject);
|
||||
});
|
||||
|
||||
it('should allow to add summaries via configureTestingModule', () => {
|
||||
resetTestEnvironmentWithSummaries();
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should allow to add summaries via configureTestingModule', () => {
|
||||
resetTestEnvironmentWithSummaries();
|
||||
|
||||
@Component({template: '<div someDir></div>'})
|
||||
class TestComp {
|
||||
}
|
||||
@Component({template: '<div someDir></div>'})
|
||||
class TestComp {
|
||||
}
|
||||
|
||||
TestBed
|
||||
.configureTestingModule({
|
||||
providers: [SomeDep],
|
||||
declarations: [TestComp, SomeDirective],
|
||||
aotSummaries: summaries
|
||||
})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
});
|
||||
TestBed
|
||||
.configureTestingModule({
|
||||
providers: [SomeDep],
|
||||
declarations: [TestComp, SomeDirective],
|
||||
aotSummaries: summaries
|
||||
})
|
||||
.createComponent(TestComp);
|
||||
expectInstanceCreated(SomeDirective);
|
||||
});
|
||||
|
||||
it('should allow to override a provider', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should allow to override a provider', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
const overwrittenValue = {};
|
||||
const overwrittenValue = {};
|
||||
|
||||
const fixture =
|
||||
TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []})
|
||||
.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent<SomePublicComponent>(SomePublicComponent);
|
||||
const fixture =
|
||||
TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []})
|
||||
.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent<SomePublicComponent>(SomePublicComponent);
|
||||
|
||||
expect(fixture.componentInstance.dep).toBe(overwrittenValue);
|
||||
});
|
||||
expect(fixture.componentInstance.dep).toBe(overwrittenValue);
|
||||
});
|
||||
|
||||
it('should allow to override a template', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
fixmeIvy('FW-514: ngSummary shims not generated by ngtsc') &&
|
||||
it('should allow to override a template', () => {
|
||||
resetTestEnvironmentWithSummaries(summaries);
|
||||
|
||||
TestBed.overrideTemplateUsingTestingModule(SomePublicComponent, 'overwritten');
|
||||
TestBed.overrideTemplateUsingTestingModule(SomePublicComponent, 'overwritten');
|
||||
|
||||
const fixture = TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent(SomePublicComponent);
|
||||
expectInstanceCreated(SomePublicComponent);
|
||||
const fixture =
|
||||
TestBed.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent(SomePublicComponent);
|
||||
expectInstanceCreated(SomePublicComponent);
|
||||
|
||||
expect(fixture.nativeElement).toHaveText('overwritten');
|
||||
});
|
||||
expect(fixture.nativeElement).toHaveText('overwritten');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
|
||||
{
|
||||
if (ivyEnabled) {
|
||||
fixmeIvy('unknown') && describe('ivy', () => { declareTests(); });
|
||||
describe('ivy', () => { declareTests(); });
|
||||
} else {
|
||||
describe('jit', () => { declareTests({useJit: true}); });
|
||||
describe('no jit', () => { declareTests({useJit: false}); });
|
||||
@ -52,7 +52,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
afterEach(() => { getDOM().log = originalLog; });
|
||||
|
||||
describe('events', () => {
|
||||
it('should disallow binding to attr.on*', () => {
|
||||
fixmeIvy('unknown') && it('should disallow binding to attr.on*', () => {
|
||||
const template = `<div [attr.onclick]="ctxProp"></div>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
|
||||
@ -61,7 +61,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
/Binding to event attribute 'onclick' is disallowed for security reasons, please use \(click\)=.../);
|
||||
});
|
||||
|
||||
it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => {
|
||||
fixmeIvy('unknown') && it('should disallow binding to on* with NO_ERRORS_SCHEMA', () => {
|
||||
const template = `<div [onclick]="ctxProp"></div>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
@ -72,29 +72,30 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
/Binding to event property 'onclick' is disallowed for security reasons, please use \(click\)=.../);
|
||||
});
|
||||
|
||||
it('should disallow binding to on* unless it is consumed by a directive', () => {
|
||||
const template = `<div [onPrefixedProp]="ctxProp" [onclick]="ctxProp"></div>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
fixmeIvy('unknown') &&
|
||||
it('should disallow binding to on* unless it is consumed by a directive', () => {
|
||||
const template = `<div [onPrefixedProp]="ctxProp" [onclick]="ctxProp"></div>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}}).configureTestingModule({
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
});
|
||||
|
||||
// should not throw for inputs starting with "on"
|
||||
let cmp: ComponentFixture<SecuredComponent> = undefined !;
|
||||
expect(() => cmp = TestBed.createComponent(SecuredComponent)).not.toThrow();
|
||||
// should not throw for inputs starting with "on"
|
||||
let cmp: ComponentFixture<SecuredComponent> = undefined !;
|
||||
expect(() => cmp = TestBed.createComponent(SecuredComponent)).not.toThrow();
|
||||
|
||||
// must bind to the directive not to the property of the div
|
||||
const value = cmp.componentInstance.ctxProp = {};
|
||||
cmp.detectChanges();
|
||||
const div = cmp.debugElement.children[0];
|
||||
expect(div.injector.get(OnPrefixDir).onclick).toBe(value);
|
||||
expect(getDOM().getProperty(div.nativeElement, 'onclick')).not.toBe(value);
|
||||
expect(getDOM().hasAttribute(div.nativeElement, 'onclick')).toEqual(false);
|
||||
});
|
||||
// must bind to the directive not to the property of the div
|
||||
const value = cmp.componentInstance.ctxProp = {};
|
||||
cmp.detectChanges();
|
||||
const div = cmp.debugElement.children[0];
|
||||
expect(div.injector.get(OnPrefixDir).onclick).toBe(value);
|
||||
expect(getDOM().getProperty(div.nativeElement, 'onclick')).not.toBe(value);
|
||||
expect(getDOM().hasAttribute(div.nativeElement, 'onclick')).toEqual(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('safe HTML values', function() {
|
||||
it('should not escape values marked as trusted', () => {
|
||||
fixmeIvy('unknown') && it('should not escape values marked as trusted', () => {
|
||||
const template = `<a [href]="ctxProp">Link Title</a>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
@ -108,7 +109,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
expect(getDOM().getProperty(e, 'href')).toEqual('javascript:alert(1)');
|
||||
});
|
||||
|
||||
it('should error when using the wrong trusted value', () => {
|
||||
fixmeIvy('unknown') && it('should error when using the wrong trusted value', () => {
|
||||
const template = `<a [href]="ctxProp">Link Title</a>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
@ -120,7 +121,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
expect(() => fixture.detectChanges()).toThrowError(/Required a safe URL, got a Script/);
|
||||
});
|
||||
|
||||
it('should warn when using in string interpolation', () => {
|
||||
fixmeIvy('unknown') && it('should warn when using in string interpolation', () => {
|
||||
const template = `<a href="/foo/{{ctxProp}}">Link Title</a>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
@ -153,7 +154,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
expect(value).toEqual('unsafe:javascript:alert(1)');
|
||||
}
|
||||
|
||||
it('should escape unsafe properties', () => {
|
||||
fixmeIvy('unknown') && it('should escape unsafe properties', () => {
|
||||
const template = `<a [href]="ctxProp">Link Title</a>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
@ -161,7 +162,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
checkEscapeOfHrefProperty(fixture, false);
|
||||
});
|
||||
|
||||
it('should escape unsafe attributes', () => {
|
||||
fixmeIvy('unknown') && it('should escape unsafe attributes', () => {
|
||||
const template = `<a [attr.href]="ctxProp">Link Title</a>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
@ -169,39 +170,41 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
checkEscapeOfHrefProperty(fixture, true);
|
||||
});
|
||||
|
||||
it('should escape unsafe properties if they are used in host bindings', () => {
|
||||
@Directive({selector: '[dirHref]'})
|
||||
class HrefDirective {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@HostBinding('href') @Input()
|
||||
dirHref !: string;
|
||||
}
|
||||
fixmeIvy('unknown') &&
|
||||
it('should escape unsafe properties if they are used in host bindings', () => {
|
||||
@Directive({selector: '[dirHref]'})
|
||||
class HrefDirective {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@HostBinding('href') @Input()
|
||||
dirHref !: string;
|
||||
}
|
||||
|
||||
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
|
||||
TestBed.configureTestingModule({declarations: [HrefDirective]});
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
|
||||
TestBed.configureTestingModule({declarations: [HrefDirective]});
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
|
||||
checkEscapeOfHrefProperty(fixture, false);
|
||||
});
|
||||
checkEscapeOfHrefProperty(fixture, false);
|
||||
});
|
||||
|
||||
it('should escape unsafe attributes if they are used in host bindings', () => {
|
||||
@Directive({selector: '[dirHref]'})
|
||||
class HrefDirective {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@HostBinding('attr.href') @Input()
|
||||
dirHref !: string;
|
||||
}
|
||||
fixmeIvy('unknown') &&
|
||||
it('should escape unsafe attributes if they are used in host bindings', () => {
|
||||
@Directive({selector: '[dirHref]'})
|
||||
class HrefDirective {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@HostBinding('attr.href') @Input()
|
||||
dirHref !: string;
|
||||
}
|
||||
|
||||
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
|
||||
TestBed.configureTestingModule({declarations: [HrefDirective]});
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
const template = `<a [dirHref]="ctxProp">Link Title</a>`;
|
||||
TestBed.configureTestingModule({declarations: [HrefDirective]});
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
|
||||
checkEscapeOfHrefProperty(fixture, true);
|
||||
});
|
||||
checkEscapeOfHrefProperty(fixture, true);
|
||||
});
|
||||
|
||||
it('should escape unsafe style values', () => {
|
||||
fixmeIvy('unknown') && it('should escape unsafe style values', () => {
|
||||
const template = `<div [style.background]="ctxProp">Text</div>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
@ -221,7 +224,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
expect(getDOM().getStyle(e, 'background')).not.toContain('javascript');
|
||||
});
|
||||
|
||||
it('should escape unsafe SVG attributes', () => {
|
||||
fixmeIvy('unknown') && it('should escape unsafe SVG attributes', () => {
|
||||
const template = `<svg:circle [xlink:href]="ctxProp">Text</svg:circle>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
|
||||
@ -229,7 +232,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
.toThrowError(/Can't bind to 'xlink:href'/);
|
||||
});
|
||||
|
||||
it('should escape unsafe HTML values', () => {
|
||||
fixmeIvy('unknown') && it('should escape unsafe HTML values', () => {
|
||||
const template = `<div [innerHTML]="ctxProp">Text</div>`;
|
||||
TestBed.overrideComponent(SecuredComponent, {set: {template}});
|
||||
const fixture = TestBed.createComponent(SecuredComponent);
|
||||
|
@ -16,7 +16,7 @@ import {TestBed, fakeAsync, tick} from '@angular/core/testing';
|
||||
import {fixmeIvy} from '@angular/private/testing';
|
||||
|
||||
{
|
||||
fixmeIvy('unknown') && describe('jit source mapping', () => {
|
||||
describe('jit source mapping', () => {
|
||||
let jitSpy: jasmine.Spy;
|
||||
let resourceLoader: MockResourceLoader;
|
||||
|
||||
@ -102,160 +102,167 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
function declareTests(
|
||||
{ngUrl, templateDecorator}:
|
||||
{ngUrl: string, templateDecorator: (template: string) => { [key: string]: any }}) {
|
||||
it('should use the right source url in html parse errors', fakeAsync(() => {
|
||||
@Component({...templateDecorator('<div>\n </error>')})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
expect(() => compileAndCreateComponent(MyComp))
|
||||
.toThrowError(
|
||||
new RegExp(`Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:2`));
|
||||
}));
|
||||
|
||||
it('should use the right source url in template parse errors', fakeAsync(() => {
|
||||
@Component({...templateDecorator('<div>\n <div unknown="{{ctxProp}}"></div>')})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
expect(() => compileAndCreateComponent(MyComp))
|
||||
.toThrowError(
|
||||
new RegExp(`Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:7`));
|
||||
}));
|
||||
|
||||
it('should create a sourceMap for templates', fakeAsync(() => {
|
||||
const template = `Hello World!`;
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
compileAndCreateComponent(MyComp);
|
||||
|
||||
const sourceMap = getSourceMap('ng:///DynamicTestModule/MyComp.ngfactory.js');
|
||||
expect(sourceMap.sources).toEqual([
|
||||
'ng:///DynamicTestModule/MyComp.ngfactory.js', ngUrl
|
||||
]);
|
||||
expect(sourceMap.sourcesContent).toEqual([' ', template]);
|
||||
}));
|
||||
|
||||
|
||||
it('should report source location for di errors', fakeAsync(() => {
|
||||
const template = `<div>\n <div someDir></div></div>`;
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]'})
|
||||
class SomeDir {
|
||||
constructor() { throw new Error('Test'); }
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [SomeDir]});
|
||||
let error: any;
|
||||
try {
|
||||
compileAndCreateComponent(MyComp);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
// The error should be logged from the element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 2,
|
||||
column: 4,
|
||||
source: ngUrl,
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report di errors with multiple elements and directives', fakeAsync(() => {
|
||||
const template = `<div someDir></div><div someDir="throw"></div>`;
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]'})
|
||||
class SomeDir {
|
||||
constructor(@Attribute('someDir') someDir: string) {
|
||||
if (someDir === 'throw') {
|
||||
throw new Error('Test');
|
||||
fixmeIvy('unknown') &&
|
||||
it('should use the right source url in html parse errors', fakeAsync(() => {
|
||||
@Component({...templateDecorator('<div>\n </error>')})
|
||||
class MyComp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [SomeDir]});
|
||||
let error: any;
|
||||
try {
|
||||
compileAndCreateComponent(MyComp);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
// The error should be logged from the 2nd-element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 1,
|
||||
column: 19,
|
||||
source: ngUrl,
|
||||
});
|
||||
}));
|
||||
expect(() => compileAndCreateComponent(MyComp))
|
||||
.toThrowError(new RegExp(
|
||||
`Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:2`));
|
||||
}));
|
||||
|
||||
it('should report source location for binding errors', fakeAsync(() => {
|
||||
const template = `<div>\n <span [title]="createError()"></span></div>`;
|
||||
fixmeIvy('unknown') &&
|
||||
it('should use the right source url in template parse errors', fakeAsync(() => {
|
||||
@Component({...templateDecorator('<div>\n <div unknown="{{ctxProp}}"></div>')})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
createError() { throw new Error('Test'); }
|
||||
}
|
||||
expect(() => compileAndCreateComponent(MyComp))
|
||||
.toThrowError(new RegExp(
|
||||
`Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:7`));
|
||||
}));
|
||||
|
||||
const comp = compileAndCreateComponent(MyComp);
|
||||
fixmeIvy('unknown') && it('should create a sourceMap for templates', fakeAsync(() => {
|
||||
const template = `Hello World!`;
|
||||
|
||||
let error: any;
|
||||
try {
|
||||
comp.detectChanges();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
// the stack should point to the binding
|
||||
expect(getSourcePositionForStack(error.stack)).toEqual({
|
||||
line: 2,
|
||||
column: 12,
|
||||
source: ngUrl,
|
||||
});
|
||||
// The error should be logged from the element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 2,
|
||||
column: 4,
|
||||
source: ngUrl,
|
||||
});
|
||||
}));
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
it('should report source location for event errors', fakeAsync(() => {
|
||||
const template = `<div>\n <span (click)="createError()"></span></div>`;
|
||||
compileAndCreateComponent(MyComp);
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
createError() { throw new Error('Test'); }
|
||||
}
|
||||
const sourceMap =
|
||||
getSourceMap('ng:///DynamicTestModule/MyComp.ngfactory.js');
|
||||
expect(sourceMap.sources).toEqual([
|
||||
'ng:///DynamicTestModule/MyComp.ngfactory.js', ngUrl
|
||||
]);
|
||||
expect(sourceMap.sourcesContent).toEqual([' ', template]);
|
||||
}));
|
||||
|
||||
const comp = compileAndCreateComponent(MyComp);
|
||||
|
||||
let error: any;
|
||||
const errorHandler = TestBed.get(ErrorHandler);
|
||||
spyOn(errorHandler, 'handleError').and.callFake((e: any) => error = e);
|
||||
comp.debugElement.children[0].children[0].triggerEventHandler('click', 'EVENT');
|
||||
expect(error).toBeTruthy();
|
||||
// the stack should point to the binding
|
||||
expect(getSourcePositionForStack(error.stack)).toEqual({
|
||||
line: 2,
|
||||
column: 12,
|
||||
source: ngUrl,
|
||||
});
|
||||
// The error should be logged from the element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 2,
|
||||
column: 4,
|
||||
source: ngUrl,
|
||||
});
|
||||
fixmeIvy('unknown') &&
|
||||
it('should report source location for di errors', fakeAsync(() => {
|
||||
const template = `<div>\n <div someDir></div></div>`;
|
||||
|
||||
}));
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]'})
|
||||
class SomeDir {
|
||||
constructor() { throw new Error('Test'); }
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [SomeDir]});
|
||||
let error: any;
|
||||
try {
|
||||
compileAndCreateComponent(MyComp);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
// The error should be logged from the element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 2,
|
||||
column: 4,
|
||||
source: ngUrl,
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should report di errors with multiple elements and directives', fakeAsync(() => {
|
||||
const template = `<div someDir></div><div someDir="throw"></div>`;
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]'})
|
||||
class SomeDir {
|
||||
constructor(@Attribute('someDir') someDir: string) {
|
||||
if (someDir === 'throw') {
|
||||
throw new Error('Test');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [SomeDir]});
|
||||
let error: any;
|
||||
try {
|
||||
compileAndCreateComponent(MyComp);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
// The error should be logged from the 2nd-element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 1,
|
||||
column: 19,
|
||||
source: ngUrl,
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should report source location for binding errors', fakeAsync(() => {
|
||||
const template = `<div>\n <span [title]="createError()"></span></div>`;
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
createError() { throw new Error('Test'); }
|
||||
}
|
||||
|
||||
const comp = compileAndCreateComponent(MyComp);
|
||||
|
||||
let error: any;
|
||||
try {
|
||||
comp.detectChanges();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
// the stack should point to the binding
|
||||
expect(getSourcePositionForStack(error.stack)).toEqual({
|
||||
line: 2,
|
||||
column: 12,
|
||||
source: ngUrl,
|
||||
});
|
||||
// The error should be logged from the element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 2,
|
||||
column: 4,
|
||||
source: ngUrl,
|
||||
});
|
||||
}));
|
||||
|
||||
fixmeIvy('unknown') &&
|
||||
it('should report source location for event errors', fakeAsync(() => {
|
||||
const template = `<div>\n <span (click)="createError()"></span></div>`;
|
||||
|
||||
@Component({...templateDecorator(template)})
|
||||
class MyComp {
|
||||
createError() { throw new Error('Test'); }
|
||||
}
|
||||
|
||||
const comp = compileAndCreateComponent(MyComp);
|
||||
|
||||
let error: any;
|
||||
const errorHandler = TestBed.get(ErrorHandler);
|
||||
spyOn(errorHandler, 'handleError').and.callFake((e: any) => error = e);
|
||||
comp.debugElement.children[0].children[0].triggerEventHandler('click', 'EVENT');
|
||||
expect(error).toBeTruthy();
|
||||
// the stack should point to the binding
|
||||
expect(getSourcePositionForStack(error.stack)).toEqual({
|
||||
line: 2,
|
||||
column: 12,
|
||||
source: ngUrl,
|
||||
});
|
||||
// The error should be logged from the element
|
||||
expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
|
||||
line: 2,
|
||||
column: 4,
|
||||
source: ngUrl,
|
||||
});
|
||||
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1564,7 +1564,7 @@ describe('ViewContainerRef', () => {
|
||||
});
|
||||
});
|
||||
|
||||
fixmeIvy(`Hooks don't run`) && describe('life cycle hooks', () => {
|
||||
describe('life cycle hooks', () => {
|
||||
|
||||
// Angular 5 reference: https://stackblitz.com/edit/lifecycle-hooks-vcref
|
||||
const log: string[] = [];
|
||||
@ -1608,206 +1608,216 @@ describe('ViewContainerRef', () => {
|
||||
});
|
||||
}
|
||||
|
||||
it('should call all hooks in correct order when creating with createEmbeddedView', () => {
|
||||
function SomeComponent_Template_0(rf: RenderFlags, ctx: any) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
element(0, 'hooks');
|
||||
}
|
||||
if (rf & RenderFlags.Update) {
|
||||
elementProperty(0, 'name', bind('C'));
|
||||
}
|
||||
}
|
||||
fixmeIvy(`Hooks don't run`) &&
|
||||
it('should call all hooks in correct order when creating with createEmbeddedView', () => {
|
||||
function SomeComponent_Template_0(rf: RenderFlags, ctx: any) {
|
||||
if (rf & RenderFlags.Create) {
|
||||
element(0, 'hooks');
|
||||
}
|
||||
if (rf & RenderFlags.Update) {
|
||||
elementProperty(0, 'name', bind('C'));
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: `
|
||||
@Component({
|
||||
template: `
|
||||
<ng-template #foo>
|
||||
<hooks [name]="'C'"></hooks>
|
||||
</ng-template>
|
||||
<hooks vcref [tplRef]="foo" [name]="'A'"></hooks>
|
||||
<hooks [name]="'B'"></hooks>
|
||||
`
|
||||
})
|
||||
class SomeComponent {
|
||||
static ngComponentDef = defineComponent({
|
||||
type: SomeComponent,
|
||||
selectors: [['some-comp']],
|
||||
factory: () => new SomeComponent(),
|
||||
consts: 4,
|
||||
vars: 3,
|
||||
template: (rf: RenderFlags, cmp: SomeComponent) => {
|
||||
if (rf & RenderFlags.Create) {
|
||||
template(
|
||||
0, SomeComponent_Template_0, 1, 1, null, [], ['foo', ''], templateRefExtractor);
|
||||
element(2, 'hooks', ['vcref', '']);
|
||||
element(3, 'hooks');
|
||||
}
|
||||
if (rf & RenderFlags.Update) {
|
||||
const tplRef = reference(1);
|
||||
elementProperty(2, 'tplRef', bind(tplRef));
|
||||
elementProperty(2, 'name', bind('A'));
|
||||
elementProperty(3, 'name', bind('B'));
|
||||
}
|
||||
},
|
||||
directives: [ComponentWithHooks, DirectiveWithVCRef]
|
||||
})
|
||||
class SomeComponent {
|
||||
static ngComponentDef = defineComponent({
|
||||
type: SomeComponent,
|
||||
selectors: [['some-comp']],
|
||||
factory: () => new SomeComponent(),
|
||||
consts: 4,
|
||||
vars: 3,
|
||||
template: (rf: RenderFlags, cmp: SomeComponent) => {
|
||||
if (rf & RenderFlags.Create) {
|
||||
template(
|
||||
0, SomeComponent_Template_0, 1, 1, null, [], ['foo', ''],
|
||||
templateRefExtractor);
|
||||
element(2, 'hooks', ['vcref', '']);
|
||||
element(3, 'hooks');
|
||||
}
|
||||
if (rf & RenderFlags.Update) {
|
||||
const tplRef = reference(1);
|
||||
elementProperty(2, 'tplRef', bind(tplRef));
|
||||
elementProperty(2, 'name', bind('A'));
|
||||
elementProperty(3, 'name', bind('B'));
|
||||
}
|
||||
},
|
||||
directives: [ComponentWithHooks, DirectiveWithVCRef]
|
||||
});
|
||||
}
|
||||
|
||||
log.length = 0;
|
||||
|
||||
const fixture = new ComponentFixture(SomeComponent);
|
||||
expect(log).toEqual([
|
||||
'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B',
|
||||
'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B',
|
||||
'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.createEmbeddedView(
|
||||
directiveInstance !.tplRef, fixture.component);
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks></hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks>C</hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'onChanges-C', 'onInit-C', 'doCheck-C', 'afterContentInit-C',
|
||||
'afterContentChecked-C', 'afterViewInit-C', 'afterViewChecked-C',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
const viewRef = directiveInstance !.vcref.detach(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.insert(viewRef !);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.remove(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'onDestroy-C', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A',
|
||||
'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
log.length = 0;
|
||||
|
||||
const fixture = new ComponentFixture(SomeComponent);
|
||||
expect(log).toEqual([
|
||||
'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B',
|
||||
'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B',
|
||||
'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.createEmbeddedView(directiveInstance !.tplRef, fixture.component);
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks></hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks>C</hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'onChanges-C', 'onInit-C', 'doCheck-C', 'afterContentInit-C',
|
||||
'afterContentChecked-C', 'afterViewInit-C', 'afterViewChecked-C', 'afterContentChecked-A',
|
||||
'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
const viewRef = directiveInstance !.vcref.detach(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.insert(viewRef !);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-C', 'afterContentChecked-C', 'afterViewChecked-C',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.remove(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'onDestroy-C', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should call all hooks in correct order when creating with createComponent', () => {
|
||||
@Component({
|
||||
template: `
|
||||
fixmeIvy(`Hooks don't run`) &&
|
||||
it('should call all hooks in correct order when creating with createComponent', () => {
|
||||
@Component({
|
||||
template: `
|
||||
<hooks vcref [name]="'A'"></hooks>
|
||||
<hooks [name]="'B'"></hooks>
|
||||
`
|
||||
})
|
||||
class SomeComponent {
|
||||
static ngComponentDef = defineComponent({
|
||||
type: SomeComponent,
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
selectors: [['some-comp']],
|
||||
factory: () => new SomeComponent(),
|
||||
consts: 2,
|
||||
vars: 2,
|
||||
template: (rf: RenderFlags, cmp: SomeComponent) => {
|
||||
if (rf & RenderFlags.Create) {
|
||||
element(0, 'hooks', ['vcref', '']);
|
||||
element(1, 'hooks');
|
||||
}
|
||||
if (rf & RenderFlags.Update) {
|
||||
elementProperty(0, 'name', bind('A'));
|
||||
elementProperty(1, 'name', bind('B'));
|
||||
}
|
||||
},
|
||||
directives: [ComponentWithHooks, DirectiveWithVCRef]
|
||||
})
|
||||
class SomeComponent {
|
||||
static ngComponentDef = defineComponent({
|
||||
type: SomeComponent,
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
selectors: [['some-comp']],
|
||||
factory: () => new SomeComponent(),
|
||||
consts: 2,
|
||||
vars: 2,
|
||||
template: (rf: RenderFlags, cmp: SomeComponent) => {
|
||||
if (rf & RenderFlags.Create) {
|
||||
element(0, 'hooks', ['vcref', '']);
|
||||
element(1, 'hooks');
|
||||
}
|
||||
if (rf & RenderFlags.Update) {
|
||||
elementProperty(0, 'name', bind('A'));
|
||||
elementProperty(1, 'name', bind('B'));
|
||||
}
|
||||
},
|
||||
directives: [ComponentWithHooks, DirectiveWithVCRef]
|
||||
});
|
||||
}
|
||||
|
||||
log.length = 0;
|
||||
|
||||
const fixture = new ComponentFixture(SomeComponent);
|
||||
expect(log).toEqual([
|
||||
'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B',
|
||||
'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B',
|
||||
'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
const componentRef = directiveInstance !.vcref.createComponent(
|
||||
directiveInstance !.cfr.resolveComponentFactory(ComponentWithHooks));
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks></hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([]);
|
||||
|
||||
componentRef.instance.name = 'D';
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks>D</hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'onChanges-D', 'onInit-D', 'doCheck-D', 'afterContentInit-D',
|
||||
'afterContentChecked-D', 'afterViewInit-D', 'afterViewChecked-D',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
const viewRef = directiveInstance !.vcref.detach(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.insert(viewRef !);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.remove(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'onDestroy-D', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A',
|
||||
'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
log.length = 0;
|
||||
|
||||
const fixture = new ComponentFixture(SomeComponent);
|
||||
expect(log).toEqual([
|
||||
'onChanges-A', 'onInit-A', 'doCheck-A', 'onChanges-B', 'onInit-B', 'doCheck-B',
|
||||
'afterContentInit-A', 'afterContentChecked-A', 'afterContentInit-B',
|
||||
'afterContentChecked-B', 'afterViewInit-A', 'afterViewChecked-A', 'afterViewInit-B',
|
||||
'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
const componentRef = directiveInstance !.vcref.createComponent(
|
||||
directiveInstance !.cfr.resolveComponentFactory(ComponentWithHooks));
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks></hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([]);
|
||||
|
||||
componentRef.instance.name = 'D';
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(fixture.html).toEqual('<hooks vcref="">A</hooks><hooks>D</hooks><hooks>B</hooks>');
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'onChanges-D', 'onInit-D', 'doCheck-D', 'afterContentInit-D',
|
||||
'afterContentChecked-D', 'afterViewInit-D', 'afterViewChecked-D', 'afterContentChecked-A',
|
||||
'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
const viewRef = directiveInstance !.vcref.detach(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.insert(viewRef !);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'doCheck-A', 'doCheck-B', 'doCheck-D', 'afterContentChecked-D', 'afterViewChecked-D',
|
||||
'afterContentChecked-A', 'afterContentChecked-B', 'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
|
||||
log.length = 0;
|
||||
directiveInstance !.vcref.remove(0);
|
||||
fixture.update();
|
||||
expect(log).toEqual([
|
||||
'onDestroy-D', 'doCheck-A', 'doCheck-B', 'afterContentChecked-A', 'afterContentChecked-B',
|
||||
'afterViewChecked-A', 'afterViewChecked-B'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('host bindings', () => {
|
||||
|
@ -114,10 +114,10 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(debugCtx.nodeIndex).toBe(1);
|
||||
});
|
||||
|
||||
fixmeIvy('unknown') && describe('deps', () => {
|
||||
describe('deps', () => {
|
||||
class Dep {}
|
||||
|
||||
it('should inject deps from the same element', () => {
|
||||
fixmeIvy('unknown') && it('should inject deps from the same element', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 2, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, Dep, []),
|
||||
@ -127,7 +127,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep instanceof Dep).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should inject deps from a parent element', () => {
|
||||
fixmeIvy('unknown') && it('should inject deps from a parent element', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 3, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, Dep, []),
|
||||
@ -138,7 +138,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep instanceof Dep).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not inject deps from sibling root elements', () => {
|
||||
fixmeIvy('unknown') && it('should not inject deps from sibling root elements', () => {
|
||||
const rootElNodes = [
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, Dep, []),
|
||||
@ -167,7 +167,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
' NullInjectorError: No provider for Dep!');
|
||||
});
|
||||
|
||||
it('should inject from a parent element in a parent view', () => {
|
||||
fixmeIvy('unknown') && it('should inject from a parent element in a parent view', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(
|
||||
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
|
||||
@ -181,7 +181,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep instanceof Dep).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should throw for missing dependencies', () => {
|
||||
fixmeIvy('unknown') && it('should throw for missing dependencies', () => {
|
||||
expect(() => createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, ['nonExistingDep'])
|
||||
@ -192,7 +192,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
' NullInjectorError: No provider for nonExistingDep!');
|
||||
});
|
||||
|
||||
it('should use null for optional missing dependencies', () => {
|
||||
fixmeIvy('unknown') && it('should use null for optional missing dependencies', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(
|
||||
@ -202,7 +202,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep).toBe(null);
|
||||
});
|
||||
|
||||
it('should skip the current element when using SkipSelf', () => {
|
||||
fixmeIvy('unknown') && it('should skip the current element when using SkipSelf', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 4, 'span'),
|
||||
providerDef(NodeFlags.TypeValueProvider, null, 'someToken', 'someParentValue', []),
|
||||
@ -214,18 +214,19 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep).toBe('someParentValue');
|
||||
});
|
||||
|
||||
it('should ask the root injector',
|
||||
withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep'])
|
||||
]));
|
||||
fixmeIvy('unknown') &&
|
||||
it('should ask the root injector',
|
||||
withModule({providers: [{provide: 'rootDep', useValue: 'rootValue'}]}, () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, ['rootDep'])
|
||||
]));
|
||||
|
||||
expect(instance.dep).toBe('rootValue');
|
||||
}));
|
||||
expect(instance.dep).toBe('rootValue');
|
||||
}));
|
||||
|
||||
describe('builtin tokens', () => {
|
||||
it('should inject ViewContainerRef', () => {
|
||||
fixmeIvy('unknown') && it('should inject ViewContainerRef', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
anchorDef(NodeFlags.EmbeddedViews, null, null, 1),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ViewContainerRef]),
|
||||
@ -234,7 +235,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep.createEmbeddedView).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should inject TemplateRef', () => {
|
||||
fixmeIvy('unknown') && it('should inject TemplateRef', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
anchorDef(NodeFlags.None, null, null, 1, null, compViewDefFactory([anchorDef(
|
||||
NodeFlags.None, null, null, 0)])),
|
||||
@ -244,7 +245,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep.createEmbeddedView).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should inject ElementRef', () => {
|
||||
fixmeIvy('unknown') && it('should inject ElementRef', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ElementRef]),
|
||||
@ -253,7 +254,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep.nativeElement).toBe(asElementData(view, 0).renderElement);
|
||||
});
|
||||
|
||||
it('should inject Injector', () => {
|
||||
fixmeIvy('unknown') && it('should inject Injector', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, [Injector]),
|
||||
@ -262,30 +263,32 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep.get(SomeService)).toBe(instance);
|
||||
});
|
||||
|
||||
it('should inject ChangeDetectorRef for non component providers', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef])
|
||||
]));
|
||||
fixmeIvy('unknown') &&
|
||||
it('should inject ChangeDetectorRef for non component providers', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 1, 'span'),
|
||||
directiveDef(1, NodeFlags.None, null, 0, SomeService, [ChangeDetectorRef])
|
||||
]));
|
||||
|
||||
expect(instance.dep._view).toBe(view);
|
||||
});
|
||||
expect(instance.dep._view).toBe(view);
|
||||
});
|
||||
|
||||
it('should inject ChangeDetectorRef for component providers', () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(
|
||||
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
|
||||
() => compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 0, 'span'),
|
||||
])),
|
||||
directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]),
|
||||
]));
|
||||
fixmeIvy('unknown') &&
|
||||
it('should inject ChangeDetectorRef for component providers', () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(
|
||||
0, NodeFlags.None, null, null, 1, 'div', null, null, null, null,
|
||||
() => compViewDef([
|
||||
elementDef(0, NodeFlags.None, null, null, 0, 'span'),
|
||||
])),
|
||||
directiveDef(1, NodeFlags.Component, null, 0, SomeService, [ChangeDetectorRef]),
|
||||
]));
|
||||
|
||||
const compView = asElementData(view, 0).componentView;
|
||||
expect(instance.dep._view).toBe(compView);
|
||||
});
|
||||
const compView = asElementData(view, 0).componentView;
|
||||
expect(instance.dep._view).toBe(compView);
|
||||
});
|
||||
|
||||
it('should inject RendererV1', () => {
|
||||
fixmeIvy('unknown') && it('should inject RendererV1', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(
|
||||
0, NodeFlags.None, null, null, 1, 'span', null, null, null, null,
|
||||
@ -296,7 +299,7 @@ import {fixmeIvy} from '@angular/private/testing';
|
||||
expect(instance.dep.createElement).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should inject Renderer2', () => {
|
||||
fixmeIvy('unknown') && it('should inject Renderer2', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(
|
||||
0, NodeFlags.None, null, null, 1, 'span', null, null, null, null,
|
||||
|
Loading…
x
Reference in New Issue
Block a user