htmx/test/tests/unit/htmx.config.implicitInheritance.js
MichaelWest22 46c978c912
Attribute value only return string again (#3493)
* move attributeValue back to return string and optinally return source only for this target

* remove fetchOverride

---------

Co-authored-by: MichaelWest22 <michael.west@docuvera.com>
2025-11-06 19:35:20 -07:00

61 lines
2.1 KiB
JavaScript

describe('htmx.config.implicitInheritance test', function() {
beforeEach(function() {
setupTest(this);
htmx.config.implicitInheritance = true;
});
afterEach(function() {
cleanupTest();
htmx.config.implicitInheritance = false;
});
it('child inherits attribute without :inherited modifier when implicitInheritance is true', function() {
const container = createDisconnectedHTML(
'<div hx-target="#result">' +
' <button>Test</button>' +
'</div>'
);
const button = container.querySelector('button');
const result = htmx.__attributeValue(button, 'hx-target');
assert.equal(result, '#result');
});
it('direct attribute takes precedence over inherited when implicitInheritance is true', function() {
const container = createDisconnectedHTML(
'<div hx-target="#parent">' +
' <button hx-target="#child">Test</button>' +
'</div>'
);
const button = container.querySelector('button');
const result = htmx.__attributeValue(button, 'hx-target');
assert.equal(result, '#child');
});
it('inherits through multiple levels when implicitInheritance is true', function() {
const container = createDisconnectedHTML(
'<div hx-swap="outerHTML">' +
' <div>' +
' <button>Test</button>' +
' </div>' +
'</div>'
);
const button = container.querySelector('button');
const result = htmx.__attributeValue(button, 'hx-swap');
assert.equal(result, 'outerHTML');
});
it(':append works with implicit inheritance', function() {
const container = createDisconnectedHTML(
'<div hx-vals=\'{"a":1}\'>' +
' <button hx-vals:append=\'{"b":2}\'>Test</button>' +
'</div>'
);
const button = container.querySelector('button');
const result = htmx.__attributeValue(button, 'hx-vals');
assert.equal(result, '{"a":1},{"b":2}');
});
});