summaryrefslogtreecommitdiffstatshomepage
path: root/www/static/test/attributes/hx-post.js
blob: 6734e30d21ec4e6b20add8c3c37dec4e2c3081fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
describe("hx-post attribute", function(){
    beforeEach(function() {
        this.server = makeServer();
        clearWorkArea();
    });
    afterEach(function()  {
        this.server.restore();
        clearWorkArea();
    });

    it('issues a POST request with proper headers', function()
    {
        this.server.respondWith("POST", "/test", function(xhr){
            should.equal(xhr.requestHeaders['X-HTTP-Method-Override'], undefined);
            xhr.respond(200, {}, "Posted!");
        });

        var btn = make('<button hx-post="/test">Click Me!</button>')
        btn.click();
        this.server.respond();
        btn.innerHTML.should.equal("Posted!");
    });

    it('issues a POST request with proper headers  w/ data-* prefix', function()
    {
        this.server.respondWith("POST", "/test", function(xhr){
            should.equal(xhr.requestHeaders['X-HTTP-Method-Override'], undefined);
            xhr.respond(200, {}, "Posted!");
        });

        var btn = make('<button data-hx-post="/test">Click Me!</button>')
        btn.click();
        this.server.respond();
        btn.innerHTML.should.equal("Posted!");
    });
})