From 758f7a7d8ece9d24b84332f43088388c1c3752f3 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Wed, 11 Dec 2019 22:04:31 +0100 Subject: [PATCH] test(ivy): account for inconsistent attribute order (#34305) We've got some tests that assert that the generate DOM looks correct. The problem is that IE changes the attribute order in `innerHTML` which caused the tests to fail. I've reworked the relevant tests not to assert directly against `innerHTML`. PR Close #34305 --- packages/core/test/acceptance/i18n_spec.ts | 36 +++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/packages/core/test/acceptance/i18n_spec.ts b/packages/core/test/acceptance/i18n_spec.ts index a3a44ae8cb..a1e0be58dd 100644 --- a/packages/core/test/acceptance/i18n_spec.ts +++ b/packages/core/test/acceptance/i18n_spec.ts @@ -1451,13 +1451,13 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { @Component({ selector: `my-app`, template: ` -
+
trad: {exp1, plural, =0 {no emails!} =1 {one email} other {{{exp1}} emails} } -
` +
` }) class MyApp { exp1 = 1; @@ -1476,19 +1476,27 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { }); const fixture = TestBed.createComponent(MyApp); fixture.detectChanges(); - expect(fixture.nativeElement.innerHTML) - .toEqual( - `
traduction: un email ` + - `
`); + + const outerDiv: HTMLElement = fixture.nativeElement.querySelector('div[outer]'); + const innerDiv: HTMLElement = fixture.nativeElement.querySelector('div[inner]'); + + // Note that ideally we'd just compare the innerHTML here, but different browsers return + // the order of attributes differently. E.g. most browsers preserve the declaration order, + // but IE does not. + expect(outerDiv.getAttribute('title')).toBe('début 2 milieu 1 fin'); + expect(outerDiv.getAttribute('class')).toBe('foo'); + expect(outerDiv.textContent !.trim()).toBe('traduction: un email'); + expect(innerDiv.getAttribute('class')).toBe('foo'); directiveInstances.forEach(instance => instance.klass = 'bar'); fixture.componentRef.instance.exp1 = 2; fixture.componentRef.instance.exp2 = 3; fixture.detectChanges(); - expect(fixture.nativeElement.innerHTML) - .toEqual( - `
traduction: 2 emails ` + - `
`); + + expect(outerDiv.getAttribute('title')).toBe('début 3 milieu 2 fin'); + expect(outerDiv.getAttribute('class')).toBe('bar'); + expect(outerDiv.textContent !.trim()).toBe('traduction: 2 emails'); + expect(innerDiv.getAttribute('class')).toBe('bar'); }); it('should handle i18n attribute with directive inputs', () => { @@ -2033,9 +2041,15 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { const fixture = TestBed.createComponent(ContentElementDialog); fixture.detectChanges(); + + // Remove the reflect attribute, because the attribute order in innerHTML + // isn't guaranteed in different browsers so it could throw off our assertions. + const button = fixture.nativeElement.querySelector('button'); + button.removeAttribute('ng-reflect-dialog-result'); + expect(fixture.nativeElement.innerHTML).toEqual(`
`); +}-->`); }); });