| 1 | describe('htmx.config.metaCharacter functionality', function() { |
| 2 | |
| 3 | beforeEach(function() { |
| 4 | setupTest(this); |
| 5 | htmx.config.metaCharacter = "-"; |
| 6 | }); |
| 7 | |
| 8 | afterEach(function() { |
| 9 | cleanupTest(); |
| 10 | htmx.config.metaCharacter = null; |
| 11 | }); |
| 12 | |
| 13 | it('works with inherited modifier using custom meta character', async function() { |
| 14 | mockResponse('GET', '/test', 'Success'); |
| 15 | createProcessedHTML('<div hx-target-inherited="#output"><button hx-get="/test" id="btn">Click</button><output id="output"></output></div>'); |
| 16 | find('#btn').click() |
| 17 | await forRequest(); |
| 18 | var output = find("#output"); |
| 19 | output.innerText.should.equal("Success") |
| 20 | }); |
| 21 | |
| 22 | it('works with append modifier using custom meta character', function() { |
| 23 | const container = createDisconnectedHTML( |
| 24 | '<div hx-vals-inherited=\'"a":1\'>' + |
| 25 | ' <button hx-vals-append=\'"b":2\'>Test</button>' + |
| 26 | '</div>' |
| 27 | ); |
| 28 | const button = container.querySelector('button'); |
| 29 | const result = htmx.__attributeValue(button, 'hx-vals'); |
| 30 | assert.equal(result, '"a":1,"b":2'); |
| 31 | }); |
| 32 | |
| 33 | it('works with inherited-append modifier using custom meta character', function() { |
| 34 | const container = createDisconnectedHTML( |
| 35 | '<div hx-vals-inherited=\'"a":1\'>' + |
| 36 | ' <div hx-vals-inherited-append=\'"b":2\'>' + |
| 37 | ' <button hx-vals-append=\'"c":3\'>Test</button>' + |
| 38 | ' </div>' + |
| 39 | '</div>' |
| 40 | ); |
| 41 | const button = container.querySelector('button'); |
| 42 | const result = htmx.__attributeValue(button, 'hx-vals'); |
| 43 | assert.equal(result, '"a":1,"b":2,"c":3'); |
| 44 | }); |
| 45 | |
| 46 | it('normalizes attribute names using custom meta character', function() { |
| 47 | const div = createDisconnectedHTML( |
| 48 | '<div hx-ws-connect="/ws" hx-ws-send></div>' |
| 49 | ); |
| 50 | |
| 51 | assert.equal(htmx.__attributeValue(div, 'hx-ws:connect'), '/ws'); |
| 52 | assert.equal(htmx.__attributeValue(div, 'hx-ws:send'), ''); |
| 53 | }); |
| 54 | |
| 55 | it('onLoad works with custom meta character', function() { |
| 56 | let fired = false; |
| 57 | htmx.onLoad(() => fired = true); |
| 58 | createProcessedHTML('<div hx-get="/test">Test</div>'); |
| 59 | assert.isTrue(fired); |
| 60 | }); |
| 61 | |
| 62 | it('works with hx-on events using custom meta character', async function() { |
| 63 | let eventFired = false; |
| 64 | createProcessedHTML('<button id="btn" hx-on-click="window.testEvent = true">Click</button>'); |
| 65 | |
| 66 | find('#btn').click(); |
| 67 | await htmx.timeout(50); |
| 68 | |
| 69 | assert.equal(window.testEvent, true); |
| 70 | delete window.testEvent; |
| 71 | }); |
| 72 | |
| 73 | }); |