-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
39 lines (32 loc) · 1.01 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
/* global beforeEach describe it */
import assert from 'assert'
import { JSDOM } from 'jsdom'
const testScript = 'https://unpkg.com/fetch'
const htmlTemplate = '<!DOCTYPE html><body></body></html>'
function reRequire(module) {
delete require.cache[require.resolve(module)]
return require(module)
}
describe('loadScript', () => {
const jsdom = new JSDOM(htmlTemplate)
global.document = jsdom.window.document
let loadScript
beforeEach(() => {
global.document.body.innerHTML = '<script></script>'
loadScript = reRequire('./index').default
})
it('should return promise', () => {
const promise = loadScript(testScript)
assert(promise instanceof Promise)
})
it('should load script successfully', done => {
loadScript(testScript).then(done)
const element = document.querySelector('[src]')
element.onload()
})
it('should handle loading error', done => {
loadScript(testScript).then(() => {}, done)
const element = document.querySelector('[src]')
element.onerror()
})
})