Debian Codegraph @

test/tests/attributes/hx-post.js

raw symbols SCIP
1 describe('hx-post attribute', function() {
2
3 beforeEach(() => {
4 setupTest(this.currentTest)
5 })
6
7 afterEach(() => {
8 cleanupTest(this.currentTest)
9 })
10
11 it('issues a POST request with proper headers', async function() {
12 mockResponse('POST', '/test', 'Posted!')
13 let btn = createProcessedHTML('<button hx-post="/test">Click Me!</button>')
14 btn.click()
15 await forRequest()
16 fetchMock.calls[0].request.method.should.equal('POST');
17 should.equal(fetchMock.calls[0].request.headers['X-HTTP-Method-Override'], undefined);
18 btn.innerHTML.should.equal('Posted!')
19 })
20
21 it('issues a POST request with empty string action (current URL)', async function() {
22 mockResponse('POST', /^$/, 'Posted!')
23 let btn = createProcessedHTML('<button hx-post="">Click Me!</button>')
24 btn.click()
25 await forRequest()
26 fetchMock.calls[0].request.method.should.equal('POST');
27 fetchMock.calls[0].url.should.equal('');
28 btn.innerHTML.should.equal('Posted!')
29 })
30
31 })