Skip to content

Commit bcbb76d

Browse files
setup jsdom-global to test vue component properly
1 parent 38c9a4d commit bcbb76d

File tree

4 files changed

+345
-5
lines changed

4 files changed

+345
-5
lines changed

mocha-bootstrap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// jsdom setup must be done before importing Vue
2+
import jsdom from 'jsdom-global'
3+
jsdom()
4+
process.env.NODE_ENV = 'test'

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"prebuild:dist": "rm -rf dist/*",
1818
"build:dist": "rollup -c && rollup -c --environment PRODUCTION",
1919
"build:watch": "npm run build:lib -- --watch",
20-
"test": "mocha \"./src/**/*.test.js\" --require babel-core/register --timeout 5000",
20+
"test": "mocha \"./src/**/*.test.js\" --require babel-core/register --require ./mocha-bootstrap --timeout 5000",
2121
"test:watch": "npm run test -- --watch",
2222
"lint": "eslint src",
2323
"prepublish": "npm run build",
@@ -58,6 +58,8 @@
5858
"eslint-plugin-vue": "^2.0.1",
5959
"expect": "^1.20.2",
6060
"express": "^4.14.0",
61+
"jsdom": "^11.12.0",
62+
"jsdom-global": "^3.0.2",
6163
"lint-staged": "^3.2.4",
6264
"lodash": "^4.15.0",
6365
"mocha": "^3.2.0",

src/vendor/glamor/sheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ function sheetForTag(tag) {
3636
}
3737
}
3838

39-
const isBrowser = typeof document !== 'undefined'
4039
const isDev = (x => (x === 'development') || !x)(process.env.NODE_ENV)
4140
const isTest = process.env.NODE_ENV === 'test'
41+
const isBrowser = typeof document !== 'undefined' && !isTest
4242

4343
const oldIE = (() => {
4444
if(isBrowser) {

0 commit comments

Comments
 (0)