describe("Core htmx internals Tests", function() { beforeEach(function () { this.server = makeServer(); clearWorkArea(); }); afterEach(function () { this.server.restore(); clearWorkArea(); }); it("makeFragment works with janky stuff", function(){ htmx._("makeFragment")("").tagName.should.equal("BODY"); htmx._("makeFragment")("").tagName.should.equal("BODY"); //NB - the tag name should be the *parent* element hosting the HTML since we use the fragment children // for the swap htmx._("makeFragment")("").tagName.should.equal("TR"); htmx._("makeFragment")("").tagName.should.equal("TABLE"); htmx._("makeFragment")("").tagName.should.equal("COLGROUP"); htmx._("makeFragment")("").tagName.should.equal("TBODY"); }) it("makeFragment works with template wrapping", function(){ if (!supportsTemplates()) { this._runnable.title += " - Skipped as IE11 doesn't support templates" this.skip() return } try { htmx._("makeFragment")("").children.length.should.equal(0); htmx._("makeFragment")("").children.length.should.equal(0); var fragment = htmx._("makeFragment")(""); fragment.firstElementChild.tagName.should.equal("TD"); fragment = htmx._("makeFragment")(""); fragment.firstElementChild.tagName.should.equal("THEAD"); fragment = htmx._("makeFragment")(""); fragment.firstElementChild.tagName.should.equal("COL"); fragment = htmx._("makeFragment")(""); fragment.firstElementChild.tagName.should.equal("TR"); } finally { htmx.config.useTemplateFragments = false; } }) it("makeFragment works with template wrapping and funky combos", function(){ if (!supportsTemplates()) { this._runnable.title += " - Skipped as IE11 doesn't support templates" this.skip() return } htmx.config.useTemplateFragments = true; try { var fragment = htmx._("makeFragment")("
"); fragment.children[0].tagName.should.equal("TD"); fragment.children[1].tagName.should.equal("DIV"); } finally { htmx.config.useTemplateFragments = false; } }) it("set header works with non-ASCII values", function(){ var xhr = new XMLHttpRequest(); xhr.open("GET", "/dummy"); htmx._("safelySetHeaderValue")(xhr, "Example", "привет"); // unfortunately I can't test the value :/ // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest }) it("handles parseInterval correctly", function() { chai.expect(htmx.parseInterval("1ms")).to.be.equal(1); chai.expect(htmx.parseInterval("300ms")).to.be.equal(300); chai.expect(htmx.parseInterval("1s")).to.be.equal(1000) chai.expect(htmx.parseInterval("1.5s")).to.be.equal(1500) chai.expect(htmx.parseInterval("2s")).to.be.equal(2000) chai.expect(htmx.parseInterval(null)).to.be.undefined chai.expect(htmx.parseInterval("")).to.be.undefined chai.expect(htmx.parseInterval("undefined")).to.be.undefined chai.expect(htmx.parseInterval("true")).to.be.undefined chai.expect(htmx.parseInterval("false")).to.be.undefined }) it("tokenizes correctly", function() { chai.expect(htmx._("tokenizeString")("a,")).to.be.deep.equal(['a', ',']); chai.expect(htmx._("tokenizeString")("aa,")).to.be.deep.equal(['aa', ',']); chai.expect(htmx._("tokenizeString")("aa,aa")).to.be.deep.equal(['aa', ',', 'aa']); chai.expect(htmx._("tokenizeString")("aa.aa")).to.be.deep.equal(['aa', '.', 'aa']); }) it("tags respond correctly to shouldCancel", function() { var anchorThatShouldCancel = make(""); htmx._("shouldCancel")({type:'click'}, anchorThatShouldCancel).should.equal(true); var anchorThatShouldCancel = make(""); htmx._("shouldCancel")({type:'click'}, anchorThatShouldCancel).should.equal(true); var anchorThatShouldNotCancel = make(""); htmx._("shouldCancel")({type:'click'}, anchorThatShouldNotCancel).should.equal(false); var form = make("
"); htmx._("shouldCancel")({type:'submit'}, form).should.equal(true); var form = make("
"); var input = byId("i1"); htmx._("shouldCancel")({type:'click'}, input).should.equal(true); var form = make("