diff --git a/tests/scriptlets/trusted-set-attr.test.js b/tests/scriptlets/trusted-set-attr.test.js index ded7db071..5980de0e8 100644 --- a/tests/scriptlets/trusted-set-attr.test.js +++ b/tests/scriptlets/trusted-set-attr.test.js @@ -175,3 +175,36 @@ test('selector + attr + False', (assert) => { done(); }, 30); }); + +test('selector + attr + stringified object', (assert) => { + createHit(); + const attr = 'test-attr-False'; + const value = '{ playback: false }'; + const matchClassName = 'testClassFalse'; + const mismatchClassName = 'none'; + + const matchElem = createElem(matchClassName); + const mismatchElem = createElem(mismatchClassName); + + const scriptletArgs = [`.${matchClassName}`, attr, value]; + runScriptlet(name, scriptletArgs); + + assert.ok(matchElem.getAttribute(attr), `Attr ${attr} added to selector-matched element`); + assert.ok(matchElem.getAttribute(attr) === value, `New attr value ${value} is correct`); + assert.notOk(mismatchElem.getAttribute(attr), `Attr ${attr} is not added to mismatch element`); + + assert.strictEqual(window.hit, 'FIRED'); + clearGlobalProps('hit'); + + const done = assert.async(); + + changeAttr(matchElem, attr); + setTimeout(() => { + assert.ok(matchElem.getAttribute(attr) === value, `New attr val ${value} is still correct`); + assert.strictEqual(window.hit, 'FIRED'); + // Clean up test elements + matchElem.remove(); + mismatchElem.remove(); + done(); + }, 30); +});