docs: setting up mocks in non-browser env (#1630)

This commit is contained in:
Pat Cavit 2017-02-14 14:35:28 -08:00 committed by GitHub
parent dcb2f727b7
commit 03285f8279

View file

@ -34,6 +34,20 @@ To run the test, use the command `npm test`. Ospec considers any Javascript file
npm test
```
## Running mithril in a non-browser environment
Mithril has a few dependencies on globals that exist in all its supported browser environments but are missing in all non-browser environments. To work around this you can use the browser mocks that ship with the mithril npm package.
The simplest way to do this is ensure the following snippet of code runs **before** you include mithril itself in your project.
```js
// Polyfill DOM env for mithril
global.window = require("mithril/test-utils/browserMock.js")();
global.document = window.document;
```
Once that snippet has been run you can `require("mithril")` and it should be quite happy.
---
### Good testing practices