diff options
author | 2022-03-12 02:59:10 -0800 | |
---|---|---|
committer | 2022-03-12 02:59:10 -0800 | |
commit | 7b9312313363e1d63caaef5ec1f98635f2eedd2d (patch) | |
tree | ad616afd80038e9dac049c94fc685344803fc12a /integration/bunjs-only-snippets/html-rewriter.test.js | |
parent | d6831cf801a0c9e1e3f60d9c8182636cc6567d3a (diff) | |
download | bun-7b9312313363e1d63caaef5ec1f98635f2eedd2d.tar.gz bun-7b9312313363e1d63caaef5ec1f98635f2eedd2d.tar.zst bun-7b9312313363e1d63caaef5ec1f98635f2eedd2d.zip |
Implement iterator
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() |