|
| 1 | +import { DOMParser } from "../../deno-dom-wasm.ts"; |
| 2 | +import { assertStrictEquals as assertEquals } from "assert"; |
| 3 | + |
| 4 | +Deno.test("Document.title sets title element value", () => { |
| 5 | + const doc = new DOMParser().parseFromString( |
| 6 | + `<!DOCTYPE html><html><head><title>foo</title></head><body></body></html>`, |
| 7 | + "text/html", |
| 8 | + ); |
| 9 | + assertEquals(doc.title, "foo"); |
| 10 | + doc.title = "bar"; |
| 11 | + assertEquals(doc.title, "bar"); |
| 12 | + assertEquals(doc.querySelector("title")?.textContent, "bar"); |
| 13 | +}); |
| 14 | + |
| 15 | +Deno.test("Document.title adds missing title element", () => { |
| 16 | + const doc = new DOMParser().parseFromString( |
| 17 | + `<!DOCTYPE html><html><head></head><body></body></html>`, |
| 18 | + "text/html", |
| 19 | + ); |
| 20 | + assertEquals(doc.title, ""); |
| 21 | + doc.title = "foo"; |
| 22 | + assertEquals(doc.title, "foo"); |
| 23 | + assertEquals(doc.querySelector("title")?.textContent, "foo"); |
| 24 | +}); |
| 25 | + |
| 26 | +Deno.test("Document.title does not add title missing head element", () => { |
| 27 | + const doc = new DOMParser().parseFromString( |
| 28 | + `<!DOCTYPE html><html><head></head><body></body></html>`, |
| 29 | + "text/html", |
| 30 | + ); |
| 31 | + doc.head.remove(); |
| 32 | + assertEquals(doc.title, ""); |
| 33 | + doc.title = "foo"; |
| 34 | + assertEquals(doc.title, ""); |
| 35 | + assertEquals(doc.querySelector("title"), null); |
| 36 | +}); |
0 commit comments