-
Notifications
You must be signed in to change notification settings - Fork 6
/
hyperdom.js
41 lines (37 loc) · 1.28 KB
/
hyperdom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var Mount = require('./lib/mount')
var hyperdom = require('hyperdom')
var createMonkey = require('./create')
var window = require('global')
var createTestDiv = require('./lib/createTestDiv')
var extend = require('lowscore/extend')
module.exports = function (app, options) {
return new Mount(app, {
stopApp: function () {
},
startApp: function () {
if (options && options.router) {
options.router.reset()
}
var app = this.app
if (Mount.runningInNode) {
try {
var vquery = require('vdom-query')
} catch (e) {
throw new Error('you must `npm install vdom-query --save-dev` to run tests in node')
}
var vdom = hyperdom.html('body')
var monkey = createMonkey(vdom)
monkey.set({$: vquery, visibleOnly: false, document: {}})
hyperdom.appendVDom(vdom, app, extend({ requestRender: setTimeout, window: window }, options))
return monkey
} else {
var testDiv = createTestDiv()
if (options && (options.hash || options.url) && options.router) {
options.router.push(options.url || options.hash)
}
hyperdom.append(testDiv, app, extend({ requestRender: setTimeout }, options))
return createMonkey(testDiv)
}
}
}).start()
}