feat: Support setting <html> in _app template (#1617)

This commit is contained in:
Marvin Hagemeister
2023-08-11 18:40:20 +02:00
committed by GitHub
parent d601f4cef4
commit 86f92114d8
27 changed files with 414 additions and 95 deletions
+68
View File
@@ -0,0 +1,68 @@
import {
assertNotSelector,
assertSelector,
assertTextMany,
fetchHtml,
withFresh,
} from "$fresh/tests/test_utils.ts";
Deno.test("doesn't apply internal app template", async () => {
await withFresh(
"./tests/fixture_explicit_app/main.ts",
async (address) => {
const doc = await fetchHtml(`${address}`);
// Doesn't render internal app template
assertNotSelector(doc, "body body");
assertSelector(doc, "html > head");
assertSelector(doc, "html > body");
assertSelector(doc, `meta[charset="utf-8"]`);
assertSelector(
doc,
`meta[name="viewport"][content="width=device-width, initial-scale=1.0"]`,
);
assertTextMany(doc, "title", ["fresh title"]);
// Still renders page
assertSelector(doc, "body > .inner-body > .page");
},
);
});
Deno.test("user _app works with <Head>", async () => {
await withFresh(
"./tests/fixture_explicit_app/main.ts",
async (address) => {
const doc = await fetchHtml(`${address}/head`);
// Doesn't render internal app template
assertNotSelector(doc, "body body");
assertSelector(doc, "html > head");
assertSelector(doc, "html > body");
assertSelector(doc, `meta[charset="utf-8"]`);
assertSelector(
doc,
`meta[name="viewport"][content="width=device-width, initial-scale=1.0"]`,
);
assertSelector(
doc,
`meta[name="fresh"][content="test"]`,
);
// Still renders page
assertSelector(doc, "body > .inner-body > .page");
},
);
});
Deno.test("don't duplicate <title>", async () => {
await withFresh(
"./tests/fixture_explicit_app/main.ts",
async (address) => {
const doc = await fetchHtml(`${address}/title`);
assertTextMany(doc, "title", ["foo bar"]);
},
);
});