Skip to content
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/core/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ export function run(conf) {
}

// Decorate the spec title
if (!h1Elem.id) h1Elem.id = "title";
if (!h1Elem.id) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a test. @copilot, can you add a test for this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests/spec/core/title-spec.js with two tests:

  1. Verifies that when another element already has id="title", the <h1> falls back to id="document-title" and a core/title error is emitted.
  2. Verifies normal behavior (no collision) — <h1> keeps id="title" and no error is emitted.

const existing = document.getElementById("title");
if (existing && existing !== h1Elem) {
const msg =
'Another element already uses `id="title"`. ' +
"The spec's `<h1>` will use a different id to avoid a collision.";
showError(msg, name, { elements: [existing] });
h1Elem.id = "document-title";
} else {
h1Elem.id = "title";
}
}
h1Elem.classList.add("title");

setDocumentTitle(conf, h1Elem);
Expand Down