Skip to content

Commit

Permalink
add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Jan 31, 2024
1 parent c9cb3f2 commit 518c485
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/scriptlets/trusted-set-attr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 518c485

Please sign in to comment.