Fix bugs and add tests (#145)
* Fix bug when checking if elements were parsed already
parse-element.js checks if the element was already parsed by
checking for the `data-pjax-click-state` attribute. However, this
attribute was not added until the link is clicked.
Originally, there was a separate attribute, `data-pjax-enabled`,
which tracked if the element was parsed already, but that was
changed in 9a86044.
This commit merges the attributes for mouse clicks and key presses
into one and adds that attribute when the element is initially
parsed.
* More bug fixes
* Fix documentation for currentUrlFullReload
* Ignore lines from coverage if they can't be tested
* Refactor attach-link and attach-form
* Fix and refactors tests
* Add tests
* Add TS definitions for options.requestOptions
* Code cleanup
This commit was merged in pull request #145.
This commit is contained in:
@@ -57,3 +57,81 @@ tape("request headers are sent properly", function(t) {
|
||||
})
|
||||
})
|
||||
|
||||
tape("HTTP status codes other than 200 are handled properly", function(t) {
|
||||
var url = "https://httpbin.org/status/400"
|
||||
|
||||
sendRequest(url, {}, function(responseText, request) {
|
||||
t.equals(responseText, null, "responseText is null")
|
||||
t.equals(request.status, 400, "HTTP status code is correct")
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape.skip("XHR error is handled properly", function(t) {
|
||||
var url = "https://encrypted.google.com/foobar"
|
||||
|
||||
sendRequest(url, {}, function(responseText) {
|
||||
t.equals(responseText, null, "responseText is null")
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape("POST body data is sent properly", function(t) {
|
||||
var url = "https://httpbin.org/post"
|
||||
var params = [{
|
||||
name: "test",
|
||||
value: "1"
|
||||
}];
|
||||
var options = {
|
||||
requestOptions: {
|
||||
requestMethod: "POST",
|
||||
requestParams: params
|
||||
}
|
||||
}
|
||||
|
||||
sendRequest(url, options, function(responseText) {
|
||||
var response = JSON.parse(responseText)
|
||||
|
||||
t.same(response.form[params[0].name], params[0].value, "requestParams were sent properly")
|
||||
t.equals(response.headers["Content-Type"], "application/x-www-form-urlencoded", "Content-Type header was set properly")
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape("GET query data is sent properly", function(t) {
|
||||
var url = "https://httpbin.org/get"
|
||||
var params = [{
|
||||
name: "test",
|
||||
value: "1"
|
||||
}];
|
||||
var options = {
|
||||
requestOptions: {
|
||||
requestParams: params
|
||||
}
|
||||
}
|
||||
|
||||
sendRequest(url, options, function(responseText) {
|
||||
var response = JSON.parse(responseText)
|
||||
|
||||
t.same(response.args[params[0].name], params[0].value, "requestParams were sent properly")
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
tape("XHR timeout is handled properly", function(t) {
|
||||
var url = "https://httpbin.org/delay/5"
|
||||
var options = {
|
||||
timeout: 1000
|
||||
}
|
||||
|
||||
sendRequest(url, options, function(responseText) {
|
||||
t.equals(responseText, null, "responseText is null")
|
||||
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user