test(ivy): enable last test in view injector integration spec (#27989)
PR Close #27989
This commit is contained in:
parent
6e7c46af1b
commit
c2f19515d6
@ -10,7 +10,7 @@ import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, Compon
|
|||||||
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
|
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
|
||||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
import {fixmeIvy, modifiedInIvy, obsoleteInIvy, onlyInIvy} from '@angular/private/testing';
|
import {ivyEnabled, modifiedInIvy, obsoleteInIvy, onlyInIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
@Directive({selector: '[simpleDirective]'})
|
@Directive({selector: '[simpleDirective]'})
|
||||||
class SimpleDirective {
|
class SimpleDirective {
|
||||||
@ -818,37 +818,50 @@ class TestComp {
|
|||||||
expect(compEl.nativeElement).toHaveText('1');
|
expect(compEl.nativeElement).toHaveText('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
fixmeIvy(
|
it('should inject ChangeDetectorRef of the containing component into directives', () => {
|
||||||
'FW-893: expect(changeDetectorRef).toEqual(otherChangeDetectorRef) creates an infinite loop')
|
TestBed.configureTestingModule(
|
||||||
.it('should inject ChangeDetectorRef of the containing component into directives', () => {
|
{declarations: [PushComponentNeedsChangeDetectorRef, DirectiveNeedsChangeDetectorRef]});
|
||||||
TestBed.configureTestingModule({
|
TestBed.overrideComponent(PushComponentNeedsChangeDetectorRef, {
|
||||||
declarations:
|
set: {
|
||||||
[PushComponentNeedsChangeDetectorRef, DirectiveNeedsChangeDetectorRef]
|
template:
|
||||||
});
|
'{{counter}}<div directiveNeedsChangeDetectorRef></div><div *ngIf="true" directiveNeedsChangeDetectorRef></div>'
|
||||||
TestBed.overrideComponent(PushComponentNeedsChangeDetectorRef, {
|
}
|
||||||
set: {
|
});
|
||||||
template:
|
const cf = createComponentFixture('<div componentNeedsChangeDetectorRef></div>');
|
||||||
'{{counter}}<div directiveNeedsChangeDetectorRef></div><div *ngIf="true" directiveNeedsChangeDetectorRef></div>'
|
cf.detectChanges();
|
||||||
}
|
const compEl = cf.debugElement.children[0];
|
||||||
});
|
const comp: PushComponentNeedsChangeDetectorRef =
|
||||||
const cf = createComponentFixture('<div componentNeedsChangeDetectorRef></div>');
|
compEl.injector.get(PushComponentNeedsChangeDetectorRef);
|
||||||
cf.detectChanges();
|
comp.counter = 1;
|
||||||
const compEl = cf.debugElement.children[0];
|
cf.detectChanges();
|
||||||
const comp: PushComponentNeedsChangeDetectorRef =
|
expect(compEl.nativeElement).toHaveText('0');
|
||||||
compEl.injector.get(PushComponentNeedsChangeDetectorRef);
|
|
||||||
comp.counter = 1;
|
/**
|
||||||
cf.detectChanges();
|
* Compares two `ChangeDetectorRef` instances. The logic depends on the engine, as the
|
||||||
expect(compEl.nativeElement).toHaveText('0');
|
* implementation details of `ViewRef` vary.
|
||||||
expect(
|
*/
|
||||||
compEl.children[0].injector.get(DirectiveNeedsChangeDetectorRef).changeDetectorRef)
|
function _compareChangeDetectorRefs(a: ChangeDetectorRef, b: ChangeDetectorRef) {
|
||||||
.toEqual(comp.changeDetectorRef);
|
if (!ivyEnabled) {
|
||||||
expect(
|
// View Engine case
|
||||||
compEl.children[1].injector.get(DirectiveNeedsChangeDetectorRef).changeDetectorRef)
|
expect(a).toEqual(b);
|
||||||
.toEqual(comp.changeDetectorRef);
|
} else {
|
||||||
comp.changeDetectorRef.markForCheck();
|
// Ivy case
|
||||||
cf.detectChanges();
|
expect((a as any)._lView).toEqual((b as any)._lView);
|
||||||
expect(compEl.nativeElement).toHaveText('1');
|
expect((a as any).context).toEqual((b as any).context);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_compareChangeDetectorRefs(
|
||||||
|
compEl.children[0].injector.get(DirectiveNeedsChangeDetectorRef).changeDetectorRef,
|
||||||
|
comp.changeDetectorRef);
|
||||||
|
_compareChangeDetectorRefs(
|
||||||
|
compEl.children[1].injector.get(DirectiveNeedsChangeDetectorRef).changeDetectorRef,
|
||||||
|
comp.changeDetectorRef);
|
||||||
|
|
||||||
|
comp.changeDetectorRef.markForCheck();
|
||||||
|
cf.detectChanges();
|
||||||
|
expect(compEl.nativeElement).toHaveText('1');
|
||||||
|
});
|
||||||
|
|
||||||
it('should inject ChangeDetectorRef of a same element component into a directive', () => {
|
it('should inject ChangeDetectorRef of a same element component into a directive', () => {
|
||||||
TestBed.configureTestingModule(
|
TestBed.configureTestingModule(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user