From ac42ba5fcfb7014a0b24751831eeb179440aa094 Mon Sep 17 00:00:00 2001 From: Behind The Math Date: Thu, 15 Mar 2018 16:09:36 -0400 Subject: [PATCH] Add test file for TS I haven't added any tooling for this test. To check it, Typescript needs to be installed. Then run: tsc --noEmit ./tests/test.ts --- tests/test.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/test.ts diff --git a/tests/test.ts b/tests/test.ts new file mode 100644 index 0000000..4d76ad4 --- /dev/null +++ b/tests/test.ts @@ -0,0 +1,41 @@ +import Pjax = require("../index"); + +let options: Pjax.IOptions = { + elements: "a.pjax, form.pjax", + selectors: ["div.pjax"], + switches: { + "a.pjax": (oldEl, newEl) => { + oldEl.parentNode.replaceChild(newEl, oldEl); + this.onSwitch(); + }, + "form.pjax": Pjax.switches.innerHTML + }, + switchesOptions: {}, + history: true, + analytics: false, + scrollTo: 1, + scrollRestoration: false, + cacheBust: false, + debug: true, + timeout: 60000, + currentUrlFullReload: true +}; + +options.analytics = () => {}; +options.scrollTo = [1, 1]; +options.scrollTo = false; + +if (Pjax.isSupported()) { + delete options.switchesOptions; + const pjax = new Pjax(options); + + pjax.reload(); + pjax.loadUrl("https://example.org", options); + + pjax._handleResponse = pjax.handleResponse; + pjax.handleResponse = (requestText: string, request: XMLHttpRequest, href: string) => { + pjax.abortRequest(request); + + return pjax._handleResponse(requestText, request, href); + } +}