can-simple-window
A very simple, light-weight execution context (eg. browser window) which wraps around can-simple-dom. This module allows for both jQuery, CanJS, ReactJS, and other scripts to be loaded in a NodeJS environment by creating a faux browser window in which the scripts are executed. A very basic implementation of the DOM API is provided by can-simple-dom.
The API was designed to be a drop in replacement for very simple jsdom implementations. Please note that this does not support the entire jsdom
API and that can-simple-dom
is a very limited implementation of the WHATWG DOM specification. If you are looking for an environment which more closely resembles a real browser, please use jsdom
- it is a wonderful library.
simpleWindow.env(html [, scripts], callback);
Replacement for jsdom.env
var simpleWindow = ; simpleWindow;
Differences from jsdom
-
You can only pass HTML in the first parameter (no URLs or file paths)
- The html passed in is only attached to the
<body>
- no<head>
code will be processed. <script>
,<img>
,<link>
,<frame>
, and<iframe>
sources will not be loaded or processed.
- The html passed in is only attached to the
-
There is no
config
object - so the following are invalid:simpleWindow;simpleWindow; -
There are no lifecycle events for
created
oronLoad
simpleWindow.document(html);
Replacement for jsdom.jsdom
var simpleWindow = ; var document = simpleWindow;document; //-> [ H1 DOM Element ]document; //-> [ SPAN.foo DOM Element ]
Differences from jsdom
- The html passed in is only attached to the
<body>
- no<head>
code will be processed. <script>
,<img>
,<link>
,<frame>
, and<iframe>
sources will not be loaded.- There is no
options
parameter implemented.