Skip to content

Commit

Permalink
fix: Fastboot ?fastboot=false assertion hit (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
raido authored Oct 26, 2020
1 parent 4fa6ea8 commit 1ddbfd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 11 additions & 2 deletions addon/services/page-title-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ export default class PageTitleListService extends Service {
if (isFastBoot) {
this.updateFastbootTitle(toBeTitle);
} else {
/**
* When rendering app with "?fastboot=false" (http://ember-fastboot.com/docs/user-guide#disabling-fastboot)
* We will not have <title> element present in DOM.
*
* But this is fine as by HTML spec,
* one is created upon assigning "document.title" value;
*
* https://html.spec.whatwg.org/multipage/dom.html#dom-tree-accessors
*/
this.document.title = toBeTitle;
}
}
Expand All @@ -223,8 +232,8 @@ export default class PageTitleListService extends Service {
return;
}
assert(
"[ember-page-title]: Multiple or no <title> element(s) found. Check for other addons like ember-cli-head updating <title> as well.",
document.head.querySelectorAll('title').length === 1
"[ember-page-title]: Multiple title elements found. Check for other addons like ember-cli-head updating <title> as well.",
document.head.querySelectorAll('title').length <= 1
);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/acceptance/posts-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,12 @@ module('Acceptance: title', function(hooks) {

assert.equal(getPageTitle(), '(10) Reader | My App');
});

test('does not throw if no title element exist', async function (assert) {
document.head.querySelectorAll('title').forEach((titleElement) => {
document.head.removeChild(titleElement);
});
await visit('/posts');
assert.equal(getPageTitle(), 'Posts | My App');
});
});

0 comments on commit 1ddbfd3

Please sign in to comment.