2014-11-20 14:39:48 -08:00
|
|
|
var tape = require("tape")
|
|
|
|
|
|
2014-11-20 16:21:19 -08:00
|
|
|
var parseOptions = require("../../../lib/proto/parse-options.js")
|
2014-11-20 14:39:48 -08:00
|
|
|
tape("test parse initalization options function", function(t) {
|
2018-01-29 23:24:22 -05:00
|
|
|
t.test("- default options", function(t) {
|
|
|
|
|
var pjax = {};
|
|
|
|
|
parseOptions.call(pjax, {});
|
2018-01-09 00:44:20 -05:00
|
|
|
|
2018-01-29 23:24:22 -05:00
|
|
|
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");
|
2014-11-20 14:39:48 -08:00
|
|
|
|
2018-01-29 23:24:22 -05:00
|
|
|
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);
|
2018-01-09 00:44:20 -05:00
|
|
|
|
2018-01-29 23:24:22 -05:00
|
|
|
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);
|
2014-11-20 16:21:19 -08:00
|
|
|
t.end();
|
|
|
|
|
});
|
2014-11-20 14:39:48 -08:00
|
|
|
|
2018-01-09 00:44:20 -05:00
|
|
|
// verify analytics always ends up as a function even when passed not a function
|
|
|
|
|
t.test("- analytics is a function", function(t) {
|
2018-01-29 23:24:22 -05:00
|
|
|
var pjax = {};
|
|
|
|
|
parseOptions.call(pjax, {analytics: "some string"});
|
2014-11-20 14:39:48 -08:00
|
|
|
|
2018-01-29 23:24:22 -05:00
|
|
|
t.deepEqual(typeof pjax.options.analytics, "function");
|
2014-11-20 16:21:19 -08:00
|
|
|
t.end();
|
|
|
|
|
});
|
2018-01-29 23:24:22 -05:00
|
|
|
|
2018-01-09 00:44:20 -05:00
|
|
|
// verify that the value false for scrollTo is not squashed
|
|
|
|
|
t.test("- scrollTo remains false", function(t) {
|
2018-01-29 23:24:22 -05:00
|
|
|
var pjax = {};
|
|
|
|
|
parseOptions.call(pjax, {scrollTo: false});
|
2014-11-20 14:39:48 -08:00
|
|
|
|
2018-01-29 23:24:22 -05:00
|
|
|
t.deepEqual(pjax.options.scrollTo, false);
|
2014-11-20 16:21:19 -08:00
|
|
|
t.end();
|
|
|
|
|
});
|
2018-01-29 23:24:22 -05:00
|
|
|
|
2014-11-20 14:39:48 -08:00
|
|
|
t.end()
|
2018-01-09 00:44:20 -05:00
|
|
|
})
|