mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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
This commit is contained in:
committed by
Dylan Hunn
parent
a864d1c926
commit
d4015f762f
@@ -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] ' +
|
||||
|
||||
Reference in New Issue
Block a user