From d4015f762ff6d76df4c7210263d694885c2ad6d9 Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Tue, 4 Jan 2022 11:03:43 -0800 Subject: [PATCH] test: remove newlines to make a test more stable (#44616) One of the tests was not taking into account newlines in the text content of an element, thus failing in some browsers. This commit makes the test more stable by removing newlines and comparing the output after that. PR Close #44616 --- .../core/test/acceptance/view_container_ref_spec.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/test/acceptance/view_container_ref_spec.ts b/packages/core/test/acceptance/view_container_ref_spec.ts index 4a2a52e77a5..5c1bb1fbcc4 100644 --- a/packages/core/test/acceptance/view_container_ref_spec.ts +++ b/packages/core/test/acceptance/view_container_ref_spec.ts @@ -25,6 +25,15 @@ describe('ViewContainerRef', () => { .replace(/\sng-reflect-\S*="[^"]*"/g, ''); } + /** + * Helper method to retrieve the text content of the given element. This method also strips all + * leading and trailing whitespace and removes all newlines. This makes element content + * comparisons easier and less verbose. + */ + function getElementText(element: Element): string { + return element.textContent!.trim().replace(/\r?\n/g, ' '); + } + beforeEach(() => { TestBed.configureTestingModule({ declarations: [ @@ -1480,7 +1489,7 @@ describe('ViewContainerRef', () => { fixture.detectChanges(); - expect(fixture.nativeElement.parentNode.textContent.trim()) + expect(getElementText(fixture.nativeElement.parentNode)) .toContain( '[Child Component B] ' + '[Projectable Node] ' +