-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve return type of
getPageTitle
test helper
- Loading branch information
1 parent
051ccd2
commit 1a71c02
Showing
1 changed file
with
6 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// Testem appends progress to the title... | ||
// and there's no way to stop this at the moment | ||
|
||
export function getPageTitle(doc: Document) { | ||
export function getPageTitle(doc?: Document): string { | ||
// In Fastboot context we get 2 title elements if we don't remove one from app/index.html | ||
// In real world applications, it is mandatory to remove <title> from app/index.html | ||
// We are keeping both for sake for testing browser and fastboot scenarios | ||
const element = [ | ||
...(doc || window.document).querySelectorAll('head title'), | ||
].pop(); | ||
|
||
return ( | ||
element && | ||
element instanceof HTMLTitleElement && | ||
element.innerText.trim().replace(/^\(\d+\/\d+\)/, '') | ||
); | ||
if (element instanceof HTMLTitleElement) { | ||
return element.innerText.trim().replace(/^\(\d+\/\d+\)/, ''); | ||
} | ||
|
||
return ''; | ||
} |