1 | import asap from 'asap';
|
2 | import {assert} from 'chai';
|
3 | import {JSDOM} from 'jsdom';
|
4 |
|
5 | import {
|
6 | StyleSheet,
|
7 | css
|
8 | } from '../src/no-important.js';
|
9 | import { reset } from '../src/inject.js';
|
10 | import { getSheetText } from './testUtils.js';
|
11 |
|
12 | describe('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 |
|
45 | it('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 | });
|