diff --git a/src/nodes/html.ts b/src/nodes/html.ts index a9b6b2e..7471f8d 100644 --- a/src/nodes/html.ts +++ b/src/nodes/html.ts @@ -718,9 +718,7 @@ export default class HTMLElement extends Node { this.rawAttrs = Object.keys(attrs) .map((name) => { const val = this.quoteAttribute(attrs[name]); - if (val === undefined || val === 'null') { - return name; - } + if (val === 'null' || val === '""') return name; return `${name}=${val}`; }) .join(' '); diff --git a/test/tests/issues/258.js b/test/tests/issues/258.js new file mode 100644 index 0000000..09c245f --- /dev/null +++ b/test/tests/issues/258.js @@ -0,0 +1,16 @@ +const { parse } = require('@test/test-target'); + +describe('issue 258', function () { + it('removeAttribute makes boolean attributes render incorrectly.', function () { + const inputEl = parse('').firstChild + + inputEl.setAttribute('checked', ''); + inputEl.setAttribute('a', ''); + inputEl.toString().should.eql(''); + + inputEl.removeAttribute('a'); + inputEl.toString().should.eql(''); + console.log(inputEl.toString()); // => INCORRECT + // div.innerText.should.eql(`Hello World`); + }); +});