Skip to content

Commit 1ddbfd3

Browse files
authored
fix: Fastboot ?fastboot=false assertion hit (#198)
1 parent 4fa6ea8 commit 1ddbfd3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

addon/services/page-title-list.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ export default class PageTitleListService extends Service {
208208
if (isFastBoot) {
209209
this.updateFastbootTitle(toBeTitle);
210210
} else {
211+
/**
212+
* When rendering app with "?fastboot=false" (http://ember-fastboot.com/docs/user-guide#disabling-fastboot)
213+
* We will not have <title> element present in DOM.
214+
*
215+
* But this is fine as by HTML spec,
216+
* one is created upon assigning "document.title" value;
217+
*
218+
* https://html.spec.whatwg.org/multipage/dom.html#dom-tree-accessors
219+
*/
211220
this.document.title = toBeTitle;
212221
}
213222
}
@@ -223,8 +232,8 @@ export default class PageTitleListService extends Service {
223232
return;
224233
}
225234
assert(
226-
"[ember-page-title]: Multiple or no <title> element(s) found. Check for other addons like ember-cli-head updating <title> as well.",
227-
document.head.querySelectorAll('title').length === 1
235+
"[ember-page-title]: Multiple title elements found. Check for other addons like ember-cli-head updating <title> as well.",
236+
document.head.querySelectorAll('title').length <= 1
228237
);
229238
}
230239

tests/acceptance/posts-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,12 @@ module('Acceptance: title', function(hooks) {
8686

8787
assert.equal(getPageTitle(), '(10) Reader | My App');
8888
});
89+
90+
test('does not throw if no title element exist', async function (assert) {
91+
document.head.querySelectorAll('title').forEach((titleElement) => {
92+
document.head.removeChild(titleElement);
93+
});
94+
await visit('/posts');
95+
assert.equal(getPageTitle(), 'Posts | My App');
96+
});
8997
});

0 commit comments

Comments
 (0)