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
This commit is contained in:
41
tests/test.ts
Normal file
41
tests/test.ts
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user