Skip to content

Commit

Permalink
Testem adds own title element which breaks document.title
Browse files Browse the repository at this point in the history
  • Loading branch information
kzys committed Nov 7, 2019
1 parent d4b6a7c commit a6fa0fd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
9 changes: 5 additions & 4 deletions tests/acceptance/crate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { setupApplicationTest } from 'ember-qunit';
import { click, fillIn, currentURL, currentRouteName, visit } from '@ember/test-helpers';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import axeConfig from '../axe-config';
import { title } from '../helpers/dom';
import setupMirage from '../helpers/setup-mirage';
import { percySnapshot } from 'ember-percy';

Expand Down Expand Up @@ -66,7 +67,7 @@ module('Acceptance | crate page', function(hooks) {
await click('[data-test-just-updated] [data-test-crate-link="0"]');

assert.equal(currentURL(), '/crates/nanomsg');
assert.equal(document.title, 'nanomsg - crates.io: Rust Package Registry');
assert.equal(title(), 'nanomsg - crates.io: Rust Package Registry');
});

test('visiting /crates/nanomsg', async function(assert) {
Expand All @@ -78,7 +79,7 @@ module('Acceptance | crate page', function(hooks) {

assert.equal(currentURL(), '/crates/nanomsg');
assert.equal(currentRouteName(), 'crate.index');
assert.equal(document.title, 'nanomsg - crates.io: Rust Package Registry');
assert.equal(title(), 'nanomsg - crates.io: Rust Package Registry');

assert.dom('[data-test-heading] [data-test-crate-name]').hasText('nanomsg');
assert.dom('[data-test-heading] [data-test-crate-version]').hasText('0.6.1');
Expand All @@ -93,7 +94,7 @@ module('Acceptance | crate page', function(hooks) {

assert.equal(currentURL(), '/crates/nanomsg/');
assert.equal(currentRouteName(), 'crate.index');
assert.equal(document.title, 'nanomsg - crates.io: Rust Package Registry');
assert.equal(title(), 'nanomsg - crates.io: Rust Package Registry');

assert.dom('[data-test-heading] [data-test-crate-name]').hasText('nanomsg');
assert.dom('[data-test-heading] [data-test-crate-version]').hasText('0.6.1');
Expand All @@ -108,7 +109,7 @@ module('Acceptance | crate page', function(hooks) {

assert.equal(currentURL(), '/crates/nanomsg/0.6.0');
assert.equal(currentRouteName(), 'crate.version');
assert.equal(document.title, 'nanomsg - crates.io: Rust Package Registry');
assert.equal(title(), 'nanomsg - crates.io: Rust Package Registry');

assert.dom('[data-test-heading] [data-test-crate-name]').hasText('nanomsg');
assert.dom('[data-test-heading] [data-test-crate-version]').hasText('0.6.0');
Expand Down
5 changes: 3 additions & 2 deletions tests/acceptance/crates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { setupApplicationTest } from 'ember-qunit';
import { click, currentURL, visit } from '@ember/test-helpers';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import axeConfig from '../axe-config';
import { title } from '../helpers/dom';
import setupMirage from '../helpers/setup-mirage';
import { percySnapshot } from 'ember-percy';

Expand Down Expand Up @@ -42,7 +43,7 @@ module('Acceptance | crates page', function(hooks) {
await click('[data-test-all-crates-link]');

assert.equal(currentURL(), '/crates');
assert.equal(document.title, 'Crates - crates.io: Rust Package Registry');
assert.equal(title(), 'Crates - crates.io: Rust Package Registry');
});

test('visiting the crates page directly', async function(assert) {
Expand All @@ -52,7 +53,7 @@ module('Acceptance | crates page', function(hooks) {
await click('[data-test-all-crates-link]');

assert.equal(currentURL(), '/crates');
assert.equal(document.title, 'Crates - crates.io: Rust Package Registry');
assert.equal(title(), 'Crates - crates.io: Rust Package Registry');
});

test('listing crates', async function(assert) {
Expand Down
3 changes: 2 additions & 1 deletion tests/acceptance/front-page-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { setupApplicationTest } from 'ember-qunit';
import { currentURL, visit } from '@ember/test-helpers';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import axeConfig from '../axe-config';
import { title } from '../helpers/dom';
import setupMirage from '../helpers/setup-mirage';
import { percySnapshot } from 'ember-percy';

Expand All @@ -25,7 +26,7 @@ module('Acceptance | front page', function(hooks) {
await visit('/');

assert.equal(currentURL(), '/');
assert.equal(document.title, 'crates.io: Rust Package Registry');
assert.equal(title(), 'crates.io: Rust Package Registry');

assert.dom('[data-test-install-cargo-link]').exists();
assert.dom('[data-test-all-crates-link]').exists();
Expand Down
5 changes: 3 additions & 2 deletions tests/acceptance/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fillIn, currentURL, triggerEvent, visit, blur } from '@ember/test-helpe
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { triggerKeyDown, triggerKeyPress } from 'ember-keyboard';
import axeConfig from '../axe-config';
import { title } from '../helpers/dom';
import setupMirage from '../helpers/setup-mirage';
import { percySnapshot } from 'ember-percy';

Expand All @@ -30,7 +31,7 @@ module('Acceptance | search', function(hooks) {
await triggerEvent('[data-test-search-form]', 'submit');

assert.equal(currentURL(), '/search?q=rust');
assert.equal(document.title, "Search Results for 'rust' - crates.io: Rust Package Registry");
assert.equal(title(), "Search Results for 'rust' - crates.io: Rust Package Registry");

assert.dom('[data-test-heading]').hasText("Search Results for 'rust'");
assert.dom('[data-test-search-nav]').hasText('Displaying 1-8 of 8 total results');
Expand All @@ -53,7 +54,7 @@ module('Acceptance | search', function(hooks) {
await visit('/search?q=rust');

assert.equal(currentURL(), '/search?q=rust');
assert.equal(document.title, "Search Results for 'rust' - crates.io: Rust Package Registry");
assert.equal(title(), "Search Results for 'rust' - crates.io: Rust Package Registry");

assert.dom('[data-test-search-input]').hasValue('rust');
assert.dom('[data-test-heading]').hasText("Search Results for 'rust'");
Expand Down
8 changes: 8 additions & 0 deletions tests/helpers/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Because Testem adds own title element
// https://github.com/adopted-ember-addons/ember-page-title/blob/4732cdb2c9f673e4714334b33c5b4c5056dfcb8f/tests/acceptance/posts-test.js#L11
function title() {
let titles = document.head.getElementsByTagName('title');
return titles[titles.length - 1].innerText;
}

export { title };

0 comments on commit a6fa0fd

Please sign in to comment.