From 7b9312313363e1d63caaef5ec1f98635f2eedd2d Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 12 Mar 2022 02:59:10 -0800 Subject: Implement iterator --- .../bunjs-only-snippets/html-rewriter.test.js | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'integration/bunjs-only-snippets/html-rewriter.test.js') 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("
it worked!
"); }); + 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( + '
hello
' + ); + var output = rewriter.transform(input); + expect(await output.text()).toBe( + '
hello
' + ); + expect(expected.length).toBe(0); + }); + it("handles element specific mutations", async () => { // prepend/append let res = new HTMLRewriter() -- cgit v1.2.3