From 1ddbfd3f728f94e7f17bc75e963331ae4dfac102 Mon Sep 17 00:00:00 2001 From: Raido Kuli Date: Mon, 26 Oct 2020 22:52:52 +0200 Subject: [PATCH] fix: Fastboot ?fastboot=false assertion hit (#198) --- addon/services/page-title-list.js | 13 +++++++++++-- tests/acceptance/posts-test.js | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/addon/services/page-title-list.js b/addon/services/page-title-list.js index 4570b848..13bd3bfa 100644 --- a/addon/services/page-title-list.js +++ b/addon/services/page-title-list.js @@ -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 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; } } @@ -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 ); } diff --git a/tests/acceptance/posts-test.js b/tests/acceptance/posts-test.js index 22d6866f..f1a3ab55 100644 --- a/tests/acceptance/posts-test.js +++ b/tests/acceptance/posts-test.js @@ -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'); + }); });