Fix additional attributes for js renderers (#3625)
This commit is contained in:
1 parent
67515ce812
commit
2d188452ae
10 files changed
+125
-1
No files matched your search
@@ -37,3 +37,34 @@ test("hydration", async ({ page }) => {
|
||||
const mountedDiv = page.locator("div.onmounted-div");
|
||||
await expect(mountedDiv).toHaveText("onmounted was called 1 times");
|
||||
});
|
||||
|
||||
test("document elements", async ({ page }) => {
|
||||
await page.goto("http://localhost:9999");
|
||||
// wait until the meta element is mounted
|
||||
const meta = page.locator("meta#meta-head[name='testing']");
|
||||
await meta.waitFor({ state: "attached" });
|
||||
await expect(meta).toHaveAttribute("data", "dioxus-meta-element");
|
||||
|
||||
const link = page.locator("link#link-head[rel='stylesheet']");
|
||||
await link.waitFor({ state: "attached" });
|
||||
await expect(link).toHaveAttribute(
|
||||
"href",
|
||||
"https://fonts.googleapis.com/css?family=Roboto+Mono"
|
||||
);
|
||||
|
||||
const stylesheet = page.locator("link#stylesheet-head[rel='stylesheet']");
|
||||
await stylesheet.waitFor({ state: "attached" });
|
||||
await expect(stylesheet).toHaveAttribute(
|
||||
"href",
|
||||
"https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"
|
||||
);
|
||||
|
||||
const script = page.locator("script#script-head");
|
||||
await script.waitFor({ state: "attached" });
|
||||
await expect(script).toHaveAttribute("async", "true");
|
||||
|
||||
const style = page.locator("style#style-head");
|
||||
await style.waitFor({ state: "attached" });
|
||||
const main = page.locator("#main");
|
||||
await expect(main).toHaveCSS("font-family", "Roboto");
|
||||
});
|
||||
@@ -41,6 +41,7 @@ fn app() -> Element {
|
||||
Errors {}
|
||||
}
|
||||
OnMounted {}
|
||||
DocumentElements {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,3 +118,19 @@ pub fn ThrowsError() -> Element {
|
||||
"success"
|
||||
}
|
||||
}
|
||||
|
||||
/// This component tests the document::* elements pre-rendered on the server
|
||||
#[component]
|
||||
fn DocumentElements() -> Element {
|
||||
rsx! {
|
||||
document::Meta { id: "meta-head", name: "testing", data: "dioxus-meta-element" }
|
||||
document::Link {
|
||||
id: "link-head",
|
||||
rel: "stylesheet",
|
||||
href: "https://fonts.googleapis.com/css?family=Roboto+Mono"
|
||||
}
|
||||
document::Stylesheet { id: "stylesheet-head", href: "https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic" }
|
||||
document::Script { id: "script-head", async: true, "console.log('hello world');" }
|
||||
document::Style { id: "style-head", "body {{ font-family: 'Roboto'; }}" }
|
||||
}
|
||||
}
|
||||
@@ -124,3 +124,34 @@ test("web-sys closure", async ({ page }) => {
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(scrollDiv).toHaveText("the keydown event was triggered");
|
||||
});
|
||||
|
||||
test("document elements", async ({ page }) => {
|
||||
await page.goto("http://localhost:9999");
|
||||
// wait until the meta element is mounted
|
||||
const meta = page.locator("meta#meta-head[name='testing']");
|
||||
await meta.waitFor({ state: "attached" });
|
||||
await expect(meta).toHaveAttribute("data", "dioxus-meta-element");
|
||||
|
||||
const link = page.locator("link#link-head[rel='stylesheet']");
|
||||
await link.waitFor({ state: "attached" });
|
||||
await expect(link).toHaveAttribute(
|
||||
"href",
|
||||
"https://fonts.googleapis.com/css?family=Roboto+Mono"
|
||||
);
|
||||
|
||||
const stylesheet = page.locator("link#stylesheet-head[rel='stylesheet']");
|
||||
await stylesheet.waitFor({ state: "attached" });
|
||||
await expect(stylesheet).toHaveAttribute(
|
||||
"href",
|
||||
"https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic"
|
||||
);
|
||||
|
||||
const script = page.locator("script#script-head");
|
||||
await script.waitFor({ state: "attached" });
|
||||
await expect(script).toHaveAttribute("async", "true");
|
||||
|
||||
const style = page.locator("style#style-head");
|
||||
await style.waitFor({ state: "attached" });
|
||||
const main = page.locator("#main");
|
||||
await expect(main).toHaveCSS("font-family", "Roboto");
|
||||
});
|
||||
@@ -62,6 +62,7 @@ fn app() -> Element {
|
||||
PreventDefault {}
|
||||
OnMounted {}
|
||||
WebSysClosure {}
|
||||
DocumentElements {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +139,22 @@ fn WebSysClosure() -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
/// This component tests the document::* elements
|
||||
#[component]
|
||||
fn DocumentElements() -> Element {
|
||||
rsx! {
|
||||
document::Meta { id: "meta-head", name: "testing", data: "dioxus-meta-element" }
|
||||
document::Link {
|
||||
id: "link-head",
|
||||
rel: "stylesheet",
|
||||
href: "https://fonts.googleapis.com/css?family=Roboto+Mono"
|
||||
}
|
||||
document::Stylesheet { id: "stylesheet-head", href: "https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic" }
|
||||
document::Script { id: "script-head", async: true, "console.log('hello world');" }
|
||||
document::Style { id: "style-head", "body {{ font-family: 'Roboto'; }}" }
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tracing_wasm::set_as_global_default_with_config(
|
||||
tracing_wasm::WASMLayerConfigBuilder::default()
|
||||
|
||||
Reference in new issue
Block a user