From 6a03f421b333868d55686bf3a0adae96b5a63ba5 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 29 May 2022 01:41:24 +0300 Subject: [PATCH] add tests for visit attr hook --- ren/str.test.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/ren/str.test.ts b/ren/str.test.ts index 2d0617e..8fc7613 100644 --- a/ren/str.test.ts +++ b/ren/str.test.ts @@ -144,3 +144,43 @@ Deno.test({ assertEquals(res, ""); }, }); + +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, + 'hello world', + ); + }, +}); + +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, + 'hello world', + ); + }, +});