From f196604d7391e90a3d7298c3bf1a59d56fc19133 Mon Sep 17 00:00:00 2001 From: Tim Trinidad Date: Tue, 23 Jan 2018 13:22:48 -0500 Subject: [PATCH] Add tests to ensure options are not accidentally modified --- package.json | 2 +- tests/lib/proto/attach-form.js | 18 ++++++++++++++++++ tests/lib/proto/attach-link.js | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d2949c..c23931e 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "lint": "jscs . && jshint . --exclude-path .gitignore", "standalone": "browserify index.js --standalone Pjax > pjax.js", "build-debug": "browserify index.js --debug --standalone Pjax > pjax.js", - "tests": "tape -r ./tests/setup.js ./tests/**/*.js", + "tests": "tape -r ./tests/setup.js ./tests/lib/*.js ./tests/lib/proto/*.js", "test": "npm run lint && npm run tests | tap-spec", "coverage-tests": "npm run tests | tap-nyc", "coverage": "nyc -x \"tests/**\" npm run coverage-tests", diff --git a/tests/lib/proto/attach-form.js b/tests/lib/proto/attach-form.js index 701b89f..ab89543 100644 --- a/tests/lib/proto/attach-form.js +++ b/tests/lib/proto/attach-form.js @@ -76,3 +76,21 @@ tape("test attach form preventDefaulted events", function(t) { t.end() }) + +tape("test options are not modified by attachForm", function(t) { + var form = document.createElement("form") + var options = {foo: "bar"} + var loadUrl = () => {} + + attachForm.call({options, loadUrl}, form) + + var internalUri = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search + form.action = internalUri + form.method = "GET" + trigger(form, "submit") + + t.equal(1, Object.keys(options).length, "options object that is passed in should not be modified") + t.equal("bar", options.foo, "options object that is passed in should not be modified") + + t.end(); +}) diff --git a/tests/lib/proto/attach-link.js b/tests/lib/proto/attach-link.js index fef1bfc..fbaae4e 100644 --- a/tests/lib/proto/attach-link.js +++ b/tests/lib/proto/attach-link.js @@ -75,3 +75,21 @@ tape("test attach link preventDefaulted events", function(t) { t.end() }) + +tape("test options are not modified by attachLink", function(t) { + var a = document.createElement("a") + var options = {foo: "bar"} + var loadUrl = () => {}; + + attachLink.call({options, loadUrl}, a) + + var internalUri = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search + a.href = internalUri + + trigger(a, "click") + + t.equal(1, Object.keys(options).length, "options object that is passed in should not be modified") + t.equal("bar", options.foo, "options object that is passed in should not be modified") + + t.end(); +})