UNPKG

1.33 kBJavaScriptView Raw
1import asap from 'asap';
2import {assert} from 'chai';
3import {JSDOM} from 'jsdom';
4
5import {
6 StyleSheet,
7 css
8} from '../src/no-important.js';
9import { reset } from '../src/inject.js';
10import { getSheetText } from './testUtils.js';
11
12describe('css', () => {
13 beforeEach(() => {
14 global.document = new JSDOM('').window.document;
15 reset();
16 });
17
18 afterEach(() => {
19 global.document.close();
20 global.document = undefined;
21 });
22
23 it('adds styles to the DOM', done => {
24 const sheet = StyleSheet.create({
25 red: {
26 color: 'red',
27 },
28 });
29
30 css(sheet.red);
31
32 asap(() => {
33 const styleTags = global.document.getElementsByTagName("style");
34 const lastTag = styleTags[styleTags.length - 1];
35 const styles = getSheetText(lastTag.sheet);
36
37 assert.include(styles, `${sheet.red._name} {`);
38 assert.match(styles, /color: red/);
39 assert.notMatch(styles, /!important/);
40 done();
41 });
42 });
43});
44
45it('no-important exports match default package exports', () => {
46 const defaultExports = require('../src/index');
47 const noImportantExports = require('../src/no-important');
48 assert.hasAllKeys(noImportantExports, Object.keys(defaultExports));
49});