forked from node-cube/cube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcube_css.js
More file actions
59 lines (57 loc) · 2.05 KB
/
cube_css.js
File metadata and controls
59 lines (57 loc) · 2.05 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var jsdom = require('jsdom');
var expect = require('expect.js');
global.Cube = {};
var doc = '<html><head></head><body></body></html>';
global.document = jsdom.jsdom(doc);
global.window = document.parentWindow;
require('../runtime/cube_css');
function findNode(mod) {
var nodes = document.getElementsByTagName('STYLE');
var node;
nodes = Array.prototype.slice.call(nodes);
nodes.forEach(function (v) {
if (v.getAttribute('mod') === mod) {
node = v;
}
});
return node;
}
describe('runtime/cube_css.js', function () {
it.skip('should ok when parse normal css', function () {
var css = '.test div > p, a.select:active {font-weight:bolder;}';
global.Cube.css(css, '.name', 'test1.css');
var newCss = findNode('test1.css').innerHTML;
expect(newCss).match(/\.name \.test div > p/);
expect(newCss).match(/\.name a\.select:active/);
});
it.skip('should ok when parse normal css with comments', function () {
var css = '/** test */\n.test div > p, a.select:active {font-weight:bolder;}';
global.Cube.css(css, '.name', 'test1.css');
var newCss = findNode('test1.css').innerHTML;
expect(newCss).match(/\.name \/\*\* test \*\/\n\.test div > p/);
expect(newCss).match(/\.name a\.select:active/);
});
it.skip('should ok when parse normal css without namespace', function () {
var css = '/** test */\n.test div > p, a.select:active {font-weight:bolder;}';
global.Cube.css(css, undefined, 'test1.css');
var newCss = findNode('test1.css').innerHTML;
expect(newCss).eql(css);
});
it.skip('should throw error when parse error css', function () {
var css = '.test div > p {font-weight:bolder;';
try {
global.Cube.css(css, '.name', 'test2.css');
} catch (e) {
expect(e.message).to.match(/missing '\}' near line 1:35 test2.css/);
}
});
it.skip('should ok when empty css, and no style node created', function () {
var css = '';
try {
global.Cube.css(css, '.a', 'test3.css');
} catch (e) {
// nothing
}
expect(findNode('test3.css')).to.be(undefined);
});
});