-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
48 lines (37 loc) · 1.03 KB
/
test.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
42
43
44
45
46
47
48
'use strict'
var test = require('tape')
var EventTarget = require('dom-event-target')
var vm = require('vm')
var browserify = require('browserify')
test('node', function (t) {
t.doesNotThrow(function () {
require('./')
}, 'can be required')
t.throws(function () {
require('./')()
}, /browser/, 'throws when called')
t.end()
})
test('browser', function (t) {
t.plan(3)
browserify()
.require(require.resolve('./'), {
expose: 'document-ready'
})
.bundle(function (err, code) {
if (err) return t.end(err)
var document = new EventTarget()
var context = vm.createContext({
document,
setTimeout
})
vm.runInContext(code, context)
var ready = context.require('document-ready')
ready(() => t.pass('DOMContentLoaded event'))
document.send('DOMContentLoaded')
document.readyState = 'complete'
ready(() => t.pass('readyState = complete'))
document.readyState = 'interactive'
ready(() => t.pass('readyState = interactive'))
})
})