loadUrl enhancements (#134)

`loadUrl` enhancements

- Make `options` parameter optional
- Allow partial overriding of instance options when calling `loadUrl` directly
- Make `requestOptions` optional
- Document `loadUrl` usage and provide examples
This commit was merged in pull request #134.
This commit is contained in:
Robin North
2018-03-06 10:06:38 +00:00
committed by GitHub
parent f98f2dd63b
commit 05fa833169
15 changed files with 148 additions and 62 deletions

View File

@@ -1,49 +0,0 @@
var tape = require("tape")
var parseOptions = require("../../../lib/proto/parse-options.js")
tape("test parse initalization options function", function(t) {
t.test("- default options", function(t) {
var pjax = {}
parseOptions.call(pjax, {})
t.equal(pjax.options.elements, "a[href], form[action]")
t.equal(pjax.options.selectors.length, 2, "selectors length")
t.equal(pjax.options.selectors[0], "title")
t.equal(pjax.options.selectors[1], ".js-Pjax")
t.equal(typeof pjax.options.switches, "object")
t.equal(Object.keys(pjax.options.switches).length, 2)// head and body
t.equal(typeof pjax.options.switchesOptions, "object")
t.equal(Object.keys(pjax.options.switchesOptions).length, 0)
t.equal(pjax.options.history, true)
t.equal(typeof pjax.options.analytics, "function")
t.equal(pjax.options.scrollTo, 0)
t.equal(pjax.options.scrollRestoration, true)
t.equal(pjax.options.cacheBust, true)
t.equal(pjax.options.debug, false)
t.equal(pjax.options.currentUrlFullReload, false)
t.end()
})
// verify analytics always ends up as a function even when passed not a function
t.test("- analytics is a function", function(t) {
var pjax = {}
parseOptions.call(pjax, {analytics: "some string"})
t.deepEqual(typeof pjax.options.analytics, "function")
t.end()
})
// verify that the value false for scrollTo is not squashed
t.test("- scrollTo remains false", function(t) {
var pjax = {}
parseOptions.call(pjax, {scrollTo: false})
t.deepEqual(pjax.options.scrollTo, false)
t.end()
})
t.end()
})