-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from timreichen/add-document-title-setter
fix: document.title setter
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { DOMParser } from "../../deno-dom-wasm.ts"; | ||
import { assertStrictEquals as assertEquals } from "assert"; | ||
|
||
Deno.test("Document.title sets title element value", () => { | ||
const doc = new DOMParser().parseFromString( | ||
`<!DOCTYPE html><html><head><title>foo</title></head><body></body></html>`, | ||
"text/html", | ||
); | ||
assertEquals(doc.title, "foo"); | ||
doc.title = "bar"; | ||
assertEquals(doc.title, "bar"); | ||
assertEquals(doc.querySelector("title")?.textContent, "bar"); | ||
}); | ||
|
||
Deno.test("Document.title adds missing title element", () => { | ||
const doc = new DOMParser().parseFromString( | ||
`<!DOCTYPE html><html><head></head><body></body></html>`, | ||
"text/html", | ||
); | ||
assertEquals(doc.title, ""); | ||
doc.title = "foo"; | ||
assertEquals(doc.title, "foo"); | ||
assertEquals(doc.querySelector("title")?.textContent, "foo"); | ||
}); | ||
|
||
Deno.test("Document.title does not add title missing head element", () => { | ||
const doc = new DOMParser().parseFromString( | ||
`<!DOCTYPE html><html><head></head><body></body></html>`, | ||
"text/html", | ||
); | ||
doc.head.remove(); | ||
assertEquals(doc.title, ""); | ||
doc.title = "foo"; | ||
assertEquals(doc.title, ""); | ||
assertEquals(doc.querySelector("title"), null); | ||
}); |