From f854eb7dec3926c61760943de3301f2dd33581b6 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Fri, 11 Jan 2019 14:29:00 +0100 Subject: [PATCH] test(ivy): mark tests where checkNoChanges results are different in the view engine and ivy (#28073) PR Close #28073 --- .../change_detection_integration_spec.ts | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/packages/core/test/linker/change_detection_integration_spec.ts b/packages/core/test/linker/change_detection_integration_spec.ts index 197b8d6242..139a0fffeb 100644 --- a/packages/core/test/linker/change_detection_integration_spec.ts +++ b/packages/core/test/linker/change_detection_integration_spec.ts @@ -13,7 +13,7 @@ import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing'; import {By} from '@angular/platform-browser/src/dom/debug/by'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {expect} from '@angular/platform-browser/testing/src/matchers'; -import {fixmeIvy, ivyEnabled, modifiedInIvy} from '@angular/private/testing'; +import {fixmeIvy, ivyEnabled, modifiedInIvy, onlyInIvy} from '@angular/private/testing'; export function createUrlResolverWithoutPackagePrefix(): UrlResolver { return new UrlResolver(); @@ -1184,7 +1184,7 @@ const TEST_COMPILER_PROVIDERS: Provider[] = [ }); describe('enforce no new changes', () => { - fixmeIvy('FW-823: ComponentFixture.checkNoChanges doesn\'t throw under TestBed') + modifiedInIvy('checkNoChanges has no effect before first change detection run') .it('should throw when a record gets changed after it has been checked', fakeAsync(() => { @Directive({selector: '[changed]'}) class ChangingDirective { @@ -1202,6 +1202,30 @@ const TEST_COMPILER_PROVIDERS: Provider[] = [ /Previous value: 'changed: undefined'\. Current value: 'changed: 1'/g); })); + + onlyInIvy('checkNoChanges has no effect before first change detection run') + .it('should throw when a record gets changed after the first change detection pass', + fakeAsync(() => { + @Directive({selector: '[changed]'}) + class ChangingDirective { + @Input() changed: any; + } + + TestBed.configureTestingModule({declarations: [ChangingDirective]}); + + const ctx = createCompFixture('
', TestData); + + ctx.componentInstance.b = 1; + // should not throw here as change detection didn't run yet + ctx.checkNoChanges(); + + ctx.detectChanges(); + + ctx.componentInstance.b = 2; + expect(() => ctx.checkNoChanges()) + .toThrowError(/Previous value: '1'\. Current value: '2'/g); + })); + fixmeIvy('FW-831: Views created in a cd hooks throw in view engine') .it('should warn when the view has been created in a cd hook', fakeAsync(() => { const ctx = createCompFixture('
{{ a }}
', TestData); @@ -1219,7 +1243,7 @@ const TEST_COMPILER_PROVIDERS: Provider[] = [ expect(() => ctx.checkNoChanges()).not.toThrow(); })); - fixmeIvy('FW-823: ComponentFixture.checkNoChanges doesn\'t throw under TestBed') + modifiedInIvy('checkNoChanges has no effect before first change detection run') .it('should not break the next run', fakeAsync(() => { const ctx = _bindSimpleValue('a', TestData); ctx.componentInstance.a = 'value'; @@ -1228,6 +1252,19 @@ const TEST_COMPILER_PROVIDERS: Provider[] = [ ctx.detectChanges(); expect(renderLog.loggedValues).toEqual(['value']); })); + + it('should not break the next run (view engine and ivy)', fakeAsync(() => { + const ctx = _bindSimpleValue('a', TestData); + + ctx.detectChanges(); + renderLog.clear(); + + ctx.componentInstance.a = 'value'; + expect(() => ctx.checkNoChanges()).toThrow(); + + ctx.detectChanges(); + expect(renderLog.loggedValues).toEqual(['value']); + })); }); describe('mode', () => {