Skip to content

Commit

Permalink
Improve return type of getPageTitle test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Feb 15, 2024
1 parent 051ccd2 commit 1a71c02
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions addon/src/test-support/get-page-title.ts
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 '';
}

0 comments on commit 1a71c02

Please sign in to comment.