refactor(directiveLifecycle): switch test from TCB to use TestBed (#10768)
This commit is contained in:
parent
c4fd862e15
commit
895c542a20
@ -9,24 +9,32 @@
|
|||||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnInit} from '@angular/core';
|
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnInit} from '@angular/core';
|
||||||
import {Component, Directive} from '@angular/core/src/metadata';
|
import {Component, Directive} from '@angular/core/src/metadata';
|
||||||
import {ViewMetadata} from '@angular/core/src/metadata/view';
|
import {ViewMetadata} from '@angular/core/src/metadata/view';
|
||||||
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {AsyncTestCompleter, Log, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
import {AsyncTestCompleter, Log, TestComponentBuilder, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('directive lifecycle integration spec', () => {
|
describe('directive lifecycle integration spec', () => {
|
||||||
|
let log: Log;
|
||||||
beforeEachProviders(() => { return [Log]; });
|
beforeEachProviders(() => { return [Log]; });
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed
|
||||||
|
.configureTestingModule({
|
||||||
|
declarations: [
|
||||||
|
LifecycleCmp,
|
||||||
|
LifecycleDir,
|
||||||
|
MyComp5,
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.overrideComponent(MyComp5, {set: {template: '<div [field]="123" lifecycle></div>'}});
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(inject([Log], (_log: any) => { log = _log; }));
|
||||||
|
|
||||||
it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked',
|
it('should invoke lifecycle methods ngOnChanges > ngOnInit > ngDoCheck > ngAfterContentChecked',
|
||||||
inject(
|
() => {
|
||||||
[TestComponentBuilder, Log, AsyncTestCompleter],
|
let fixture = TestBed.createComponent(MyComp5);
|
||||||
(tcb: TestComponentBuilder, log: Log, async: AsyncTestCompleter) => {
|
fixture.detectChanges();
|
||||||
tcb.overrideView(MyComp5, new ViewMetadata({
|
|
||||||
template: '<div [field]="123" lifecycle></div>',
|
|
||||||
directives: [LifecycleCmp]
|
|
||||||
}))
|
|
||||||
.createAsync(MyComp5)
|
|
||||||
.then((tc) => {
|
|
||||||
tc.detectChanges();
|
|
||||||
|
|
||||||
expect(log.result())
|
expect(log.result())
|
||||||
.toEqual(
|
.toEqual(
|
||||||
@ -34,15 +42,11 @@ export function main() {
|
|||||||
'ngAfterViewInit; ngAfterViewChecked');
|
'ngAfterViewInit; ngAfterViewChecked');
|
||||||
|
|
||||||
log.clear();
|
log.clear();
|
||||||
tc.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(log.result())
|
expect(log.result())
|
||||||
.toEqual(
|
.toEqual('ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked');
|
||||||
'ngDoCheck; ngAfterContentChecked; child_ngDoCheck; ngAfterViewChecked');
|
|
||||||
|
|
||||||
async.done();
|
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +61,6 @@ class LifecycleDir implements DoCheck {
|
|||||||
selector: '[lifecycle]',
|
selector: '[lifecycle]',
|
||||||
inputs: ['field'],
|
inputs: ['field'],
|
||||||
template: `<div lifecycle-dir></div>`,
|
template: `<div lifecycle-dir></div>`,
|
||||||
directives: [LifecycleDir]
|
|
||||||
})
|
})
|
||||||
class LifecycleCmp implements OnChanges,
|
class LifecycleCmp implements OnChanges,
|
||||||
OnInit, DoCheck, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked {
|
OnInit, DoCheck, AfterContentInit, AfterContentChecked, AfterViewInit, AfterViewChecked {
|
||||||
@ -79,6 +82,6 @@ class LifecycleCmp implements OnChanges,
|
|||||||
ngAfterViewChecked() { this._log.add('ngAfterViewChecked'); }
|
ngAfterViewChecked() { this._log.add('ngAfterViewChecked'); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'my-comp', directives: []})
|
@Component({selector: 'my-comp'})
|
||||||
class MyComp5 {
|
class MyComp5 {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user