mock-window.js 893 B

12345678910111213141516171819202122232425
  1. // Mithril.js window mock factory
  2. // jshint ignore: start
  3. (function (global) {
  4. 'use strict';
  5. window.mock = function() {
  6. var window = {}
  7. window.document = global.document;
  8. window.scrollTo = function() {};
  9. window.cancelAnimationFrame = global.cancelAnimationFrame;
  10. window.requestAnimationFrame = global.requestAnimationFrame;
  11. window.XMLHttpRequest = global.XMLHttpRequest;
  12. window.location = {search: "", pathname: "", hash: ""};
  13. window.history = {};
  14. window.history.$$length = 0;
  15. window.history.pushState = function(data, title, url) {
  16. window.history.$$length++
  17. window.location.pathname = window.location.search = window.location.hash = url
  18. };
  19. window.history.replaceState = function(data, title, url) {
  20. window.location.pathname = window.location.search = window.location.hash = url
  21. };
  22. return window;
  23. };
  24. }(window));