Comparing version
{ | ||
"name": "window", | ||
"version": "3.1.5", | ||
"version": "3.1.6", | ||
"description": "Exports a jsdom window object.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -62,9 +62,11 @@ # window | ||
```js | ||
module.exports = function(text, win) { | ||
function createTitle(text, win) { | ||
win = win || window; | ||
const div = win.document.createElement('div'); | ||
div.innerHTML = `<h1>${text}</h1>`; | ||
return div.querySelector('h1'); | ||
const title = win.document.createElement('h1'); | ||
title.innerHTML = text; | ||
return title; | ||
}; | ||
module.exports = createTitle; | ||
``` | ||
@@ -75,3 +77,3 @@ | ||
```js | ||
module('Hi'); | ||
createTitle('Hi'); | ||
// <h1>Hi</h1> | ||
@@ -85,3 +87,3 @@ ``` | ||
module('Hi', window); | ||
createTitle('Hi', window); | ||
// <h1>Hi</h1> | ||
@@ -93,10 +95,10 @@ ``` | ||
```js | ||
module.exports = function(text, opts = {}) { | ||
function createTitle(text, opts = {}) { | ||
const doc = opts.document || window.document; | ||
const div = doc.createElement('div'); | ||
const title = doc.createElement('h1'); | ||
... | ||
``` | ||
You can see an example of this pattern in my `create-node` module. Specifically [src/create-node.js](https://github.com/lukechilds/create-node/blob/master/src/create-node.js) and [test/unit.js](https://github.com/lukechilds/create-node/blob/master/test/unit.js). | ||
You can see an example of this pattern in `lukechilds/create-node`. Specifically [src/create-node.js](https://github.com/lukechilds/create-node/blob/master/src/create-node.js) and [test/unit.js](https://github.com/lukechilds/create-node/blob/master/test/unit.js). | ||
@@ -103,0 +105,0 @@ ## What about dependencies? |
6331
0.06%108
1.89%