| 1 | describe('htmx.config.implicitInheritance test', function() { |
| 2 | |
| 3 | beforeEach(function() { |
| 4 | setupTest(this); |
| 5 | htmx.config.implicitInheritance = true; |
| 6 | }); |
| 7 | |
| 8 | afterEach(function() { |
| 9 | cleanupTest(); |
| 10 | htmx.config.implicitInheritance = false; |
| 11 | }); |
| 12 | |
| 13 | it('child inherits attribute without :inherited modifier when implicitInheritance is true', function() { |
| 14 | const container = createDisconnectedHTML( |
| 15 | '<div hx-target="#result">' + |
| 16 | ' <button>Test</button>' + |
| 17 | '</div>' |
| 18 | ); |
| 19 | const button = container.querySelector('button'); |
| 20 | const result = htmx.__attributeValue(button, 'hx-target'); |
| 21 | assert.equal(result, '#result'); |
| 22 | }); |
| 23 | |
| 24 | it('direct attribute takes precedence over inherited when implicitInheritance is true', function() { |
| 25 | const container = createDisconnectedHTML( |
| 26 | '<div hx-target="#parent">' + |
| 27 | ' <button hx-target="#child">Test</button>' + |
| 28 | '</div>' |
| 29 | ); |
| 30 | const button = container.querySelector('button'); |
| 31 | const result = htmx.__attributeValue(button, 'hx-target'); |
| 32 | assert.equal(result, '#child'); |
| 33 | }); |
| 34 | |
| 35 | it('inherits through multiple levels when implicitInheritance is true', function() { |
| 36 | const container = createDisconnectedHTML( |
| 37 | '<div hx-swap="outerHTML">' + |
| 38 | ' <div>' + |
| 39 | ' <button>Test</button>' + |
| 40 | ' </div>' + |
| 41 | '</div>' |
| 42 | ); |
| 43 | const button = container.querySelector('button'); |
| 44 | const result = htmx.__attributeValue(button, 'hx-swap'); |
| 45 | assert.equal(result, 'outerHTML'); |
| 46 | }); |
| 47 | |
| 48 | it(':append works with implicit inheritance', function() { |
| 49 | const container = createDisconnectedHTML( |
| 50 | '<div hx-vals=\'{"a":1}\'>' + |
| 51 | ' <button hx-vals:append=\'{"b":2}\'>Test</button>' + |
| 52 | '</div>' |
| 53 | ); |
| 54 | const button = container.querySelector('button'); |
| 55 | const result = htmx.__attributeValue(button, 'hx-vals'); |
| 56 | assert.equal(result, '"a":1,"b":2'); |
| 57 | }); |
| 58 | |
| 59 | }); |
| 60 |