Comparing version 0.3.2 to 0.4.0
@@ -26,4 +26,6 @@ /* | ||
*/ | ||
module.exports = function(window) { | ||
"use strict"; | ||
module.exports = function (window) { | ||
if (typeof window.Element === "undefined" || "classList" in window.document.documentElement) return; | ||
@@ -40,3 +42,3 @@ | ||
// to retrieve a list of classes. | ||
var classes = el.className.replace(/^\s+|\s+$/g, '').split(/\s+/); | ||
var classes = el.className.replace(/^\s+|\s+$/g, "").split(/\s+/); | ||
for (var i = 0; i < classes.length; i++) { | ||
@@ -48,3 +50,3 @@ push.call(this, classes[i]); | ||
DOMTokenList.prototype = { | ||
add: function(token) { | ||
add: function add(token) { | ||
if (this.contains(token)) return; | ||
@@ -54,9 +56,9 @@ push.call(this, token); | ||
}, | ||
contains: function(token) { | ||
contains: function contains(token) { | ||
return this.el.className.indexOf(token) != -1; | ||
}, | ||
item: function(index) { | ||
item: function item(index) { | ||
return this[index] || null; | ||
}, | ||
remove: function(token) { | ||
remove: function remove(token) { | ||
if (!this.contains(token)) return; | ||
@@ -69,6 +71,6 @@ for (var i = 0; i < this.length; i++) { | ||
}, | ||
toString: function() { | ||
return join.call(this, ' '); | ||
toString: function toString() { | ||
return join.call(this, " "); | ||
}, | ||
toggle: function(token) { | ||
toggle: function toggle(token) { | ||
if (!this.contains(token)) { | ||
@@ -96,6 +98,5 @@ this.add(token); | ||
defineElementGetter(window.Element.prototype, 'classList', function() { | ||
defineElementGetter(window.Element.prototype, "classList", function () { | ||
return new DOMTokenList(this); | ||
}); | ||
}; | ||
}; |
@@ -1,9 +0,11 @@ | ||
var jsdom = require('jsdom').jsdom; | ||
'use strict'; | ||
var actualDOM; | ||
var _jsdom = require('jsdom'); | ||
exports.create = function(domString) { | ||
var actualDOM = undefined; | ||
var create = function create(domString) { | ||
actualDOM = domString || ''; | ||
global.document = jsdom(domString || ''); | ||
global.document = (0, _jsdom.jsdom)(actualDOM); | ||
global.window = document.defaultView; | ||
@@ -19,11 +21,10 @@ global.Element = window.Element; | ||
exports.clear = function() { | ||
this.destroy(); | ||
this.create(actualDOM); | ||
var clear = function clear() { | ||
destroy(); | ||
create(actualDOM); | ||
}; | ||
exports.destroy = function(clearRequireCache) { | ||
var destroy = function destroy(clearRequireCache) { | ||
var undefined; | ||
if(clearRequireCache === undefined) { | ||
if (typeof clearRequireCache === 'undefined') { | ||
clearRequireCache = true; | ||
@@ -33,3 +34,3 @@ } | ||
window.close(); | ||
delete document; | ||
delete global.document; | ||
@@ -43,3 +44,8 @@ if (clearRequireCache) { | ||
} | ||
}; | ||
}; | ||
module.exports = { | ||
create: create, | ||
clear: clear, | ||
destroy: destroy | ||
}; |
{ | ||
"name": "jsdomify", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Create a JSDom instance for browserless testing, exposing some handling methods", | ||
@@ -13,7 +13,10 @@ "main": "lib/jsdomify.js", | ||
"devDependencies": { | ||
"babel": "5.6.23", | ||
"mocha": "2.2.5", | ||
"unexpected": "7.4.0" | ||
"unexpected": "9.2.1" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha --compilers js:babel/register", | ||
"compile": "babel -d lib/ src/", | ||
"prepublish": "npm run compile" | ||
}, | ||
@@ -20,0 +23,0 @@ "files": [ |
8640
122
3