Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelWest22 authored and botandrose-machine committed Jan 9, 2025
1 parent a13f7ba commit 3485dde
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
20 changes: 17 additions & 3 deletions test/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,27 @@ describe("Tests to ensure that the head tag merging works correctly", function (
);
});

it("can handle scripts with block mode", async function () {
it("can handle scripts with block mode with innerHTML morph", async function () {
Idiomorph.morph(
window.document,
`<head><script src='/test/lib/fixture.js'></script></head>`,
{ head: { block: true, style: "append" } },
`<head><script src='/test/lib/fixture.js'></script></head>${window.document.body.outerHTML}`,
{ morphStyle: "innerHTML", head: { block: true, style: "append" } },
);
await waitFor(() => window.hasOwnProperty("fixture"));
window.fixture.should.equal("FIXTURE");
delete(window.fixture);
window.document.head.querySelector('script[src="/test/lib/fixture.js"]').remove();
});

it("can handle scripts with block mode with outerHTML morph", async function () {
Idiomorph.morph(
window.document,
`<html><head><script src='/test/lib/fixture.js'></script></head>${window.document.body.outerHTML}</html>`,
{ morphStyle: "outerHTML", head: { block: true, style: "append" } },
);
await waitFor(() => window.hasOwnProperty("fixture"));
window.fixture.should.equal("FIXTURE");
delete(window.fixture);
window.document.head.querySelector('script[src="/test/lib/fixture.js"]').remove();
});
});
36 changes: 36 additions & 0 deletions test/htmx-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,40 @@ describe("Tests for the htmx integration", function () {
initialBtn.should.equal(newBtn);
initialBtn.classList.contains("bar").should.equal(true);
});

it("keeps the element stable in an outer morph with oob-swap", function () {
this.server.respondWith(
"GET",
"/test",
"<button id='b1' hx-swap-oob='morph'>Bar</button>",
);
let div = makeForHtmxTest(
"<div hx-get='/test' hx-swap='none'><button id='b1'>Foo</button></div>",
);
let initialBtn = document.getElementById("b1");
div.click();
this.server.respond();
let newBtn = document.getElementById("b1");
initialBtn.should.equal(newBtn);
initialBtn.innerHTML.should.equal("Bar");
});

/* Currently unable to test innerHTML style oob swaps because oob-swap syntax uses a : which conflicts with morph:innerHTML
it("keeps the element stable in an inner morph with oob-swap", function () {
this.server.respondWith(
"GET",
"/test",
"<div id='d1' hx-swap-oob='morph:innerHTML'><button id='b1'>Bar</button></button>",
);
let div = makeForHtmxTest(
"<div id='d1' hx-get='/test' hx-swap='none'><button id='b1'>Foo</button></div>",
);
let initialBtn = document.getElementById("b1");
div.click();
this.server.respond();
let newBtn = document.getElementById("b1");
initialBtn.should.equal(newBtn);
initialBtn.innerHTML.should.equal("Bar");
});
*/
});

0 comments on commit 3485dde

Please sign in to comment.