-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathinsertCss.test.js
41 lines (38 loc) · 1.29 KB
/
insertCss.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
/**
* Isomorphic CSS style loader for Webpack
*
* Copyright © 2015-present Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
import insertCss from '../src/insertCss'
describe('insertCss(styles, options)', () => {
it('Should insert and remove <style> element', () => {
const css = 'body { color: red; }'
const removeCss = insertCss([[1, css]])
let style = global.document.getElementById('s1-0')
expect(style).toBeDefined()
expect(style.textContent).toBe(css)
expect(removeCss).toBeDefined()
removeCss()
style = global.document.getElementById('s1-0')
expect(style).toBeNull
})
it('Should insert and remove multiple <style> elements for a single module', () => {
const css1 = 'body { color: red; }'
const css2 = 'body { color: blue; }'
const removeCss = insertCss([
[1, css1],
[1, css2],
])
let style = global.document.getElementsByTagName('style')
expect(style).toHaveLength(2)
expect(style[0].textContent).toBe(css1)
expect(style[1].textContent).toBe(css2)
expect(removeCss).toBeDefined()
removeCss()
style = global.document.getElementsByTagName('style')
expect(style).toHaveLength(0)
})
})