all files / tests/ no-important_test.js

100% Statements 17/17
100% Branches 0/0
100% Functions 5/5
100% Lines 17/17
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                                                 
import asap from 'asap';
import {assert} from 'chai';
import jsdom from 'jsdom';
 
import {
  StyleSheet,
  css
} from '../src/no-important.js';
import { reset } from '../src/inject.js';
 
describe('css', () => {
    beforeEach(() => {
        global.document = jsdom.jsdom();
        reset();
    });
 
    afterEach(() => {
        global.document.close();
        global.document = undefined;
    });
 
    it('adds styles to the DOM', done => {
        const sheet = StyleSheet.create({
            red: {
                color: 'red',
            },
        });
 
        css(sheet.red);
 
        asap(() => {
            const styleTags = global.document.getElementsByTagName("style");
            const lastTag = styleTags[styleTags.length - 1];
 
            assert.include(lastTag.textContent, `${sheet.red._name}{`);
            assert.match(lastTag.textContent, /color:red/);
            assert.notMatch(lastTag.textContent, /!important/);
            done();
        });
    });
});