add tests for visit attr hook

This commit is contained in:
Dmitriy Pleshevskiy 2022-05-29 01:41:24 +03:00
parent d39979645d
commit 6a03f421b3
1 changed files with 40 additions and 0 deletions

View File

@ -144,3 +144,43 @@ Deno.test({
assertEquals(res, "<!doctype html><html><body></body></html>");
},
});
Deno.test({
name: "should change attr key",
fn: () => {
const layout = E("a", {
target: "_blank",
href: "/hello/world",
rel: "nofollow noopener",
}, "hello world");
const ren = new StrRenderer({
onVisitAttr: ([key, val]) => [`data-${key}`, val],
});
const res = ren.render(layout);
assertEquals(
res,
'<a data-target="_blank" data-href="/hello/world" data-rel="nofollow noopener">hello world</a>',
);
},
});
Deno.test({
name: "should change attr value",
fn: () => {
const layout = E("a", {
href: "/hello/world",
}, "hello world");
const ren = new StrRenderer({
onVisitAttr: ([key, val]) => [key, "/eng" + val],
});
const res = ren.render(layout);
assertEquals(
res,
'<a href="/eng/hello/world">hello world</a>',
);
},
});