diff options
Diffstat (limited to 'integration/bunjs-only-snippets/html-rewriter.test.js')
-rw-r--r-- | integration/bunjs-only-snippets/html-rewriter.test.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/html-rewriter.test.js b/integration/bunjs-only-snippets/html-rewriter.test.js index 77c14e479..8990bf959 100644 --- a/integration/bunjs-only-snippets/html-rewriter.test.js +++ b/integration/bunjs-only-snippets/html-rewriter.test.js @@ -17,6 +17,34 @@ describe("HTMLRewriter", () => { expect(await output.text()).toBe("<div><blink>it worked!</blink></div>"); }); + it("supports attribute iterator", async () => { + var rewriter = new HTMLRewriter(); + var expected = [ + ["first", ""], + ["second", "alrihgt"], + ["third", "123"], + ["fourth", "5"], + ["fifth", "helloooo"], + ]; + rewriter.on("div", { + element(element2) { + for (let attr of element2.attributes) { + const stack = expected.shift(); + expect(stack[0]).toBe(attr[0]); + expect(stack[1]).toBe(attr[1]); + } + }, + }); + var input = new Response( + '<div first second="alrihgt" third="123" fourth=5 fifth=helloooo>hello</div>' + ); + var output = rewriter.transform(input); + expect(await output.text()).toBe( + '<div first second="alrihgt" third="123" fourth=5 fifth=helloooo>hello</div>' + ); + expect(expected.length).toBe(0); + }); + it("handles element specific mutations", async () => { // prepend/append let res = new HTMLRewriter() |