diff --git a/docs/mithril.deps.md b/docs/mithril.deps.md index 109b73ba..78ad61b6 100644 --- a/docs/mithril.deps.md +++ b/docs/mithril.deps.md @@ -7,11 +7,9 @@ --- -This is a testing method to set the `window` object in an environment that does not have it (such as the server). -It will normally _not_ be used in an application, as `window` is already available to Mithril. -For normal (client-side) use of mithril, this method will not be used. +This function overwrites the reference to the `window` object that is used internally by Mithril. It is useful for injecting a mock `window` dependency for the purposes of testing and for running Mithril in non-browser environments. The mock object used by Mithril for its own test suite [can be found in the development repo](https://github.com/lhorie/mithril.js/blob/next/tests/mock.js). -It is used in Mithril's testing suite, and can be used to supply a mock `window` for browserless testing. +By default, Mithril uses `window` itself as the dependency. Note that Mithril only uses the mock object for browser APIs such as the DOM API and `requestAnimationFrame`, but relies on the environment for ECMAScript features like `Object.keys`. --- @@ -42,14 +40,14 @@ where: - **Object Window** - This should be a mock of the `window` object. + This should be either `window` or a mock of the `window` object. Mithril uses certain `window` methods that will need to be made available for complete test coverage, depending on your application: - `window.document` - - Mithril also uses certain methods on the DOM node object + - Mithril also uses certain methods on the DOM node object - `window.requestAnimationFrame`/`window.cancelAnimationFrame` - - Falls back to `window.setTimeout`/`window.clearTimeout` + - Falls back to `window.setTimeout`/`window.clearTimeout` - `window.location` - `window.history` - `window.scrollTo` @@ -57,5 +55,5 @@ where: - **returns** Window - The returned window is the same as that passed in. + The returned window is the same as what is passed in. diff --git a/mithril.d.ts b/mithril.d.ts index ece7944a..4fcb5b87 100644 --- a/mithril.d.ts +++ b/mithril.d.ts @@ -20,7 +20,7 @@ interface MithrilStatic { sync(promises: MithrilPromise[]): MithrilPromise; startComputation(): void; endComputation(): void; - deps(window: any): any; + deps(Object: any): Object; } interface MithrilVirtualElement { diff --git a/tests/mock.js b/tests/mock.js index 4cd2633f..beea4423 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -68,6 +68,7 @@ mock.window = new function() { this.childNodes.splice(index, 1) child.parentNode = null } + //getElementsByTagName is only used by JSONP tests, it's not required by Mithril window.document.getElementsByTagName = function(name){ name = name.toLowerCase(); var out = [];