-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
60 lines (51 loc) · 1.52 KB
/
index.test.js
File metadata and controls
60 lines (51 loc) · 1.52 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
60
const cssJsLoader = require('../');
// Create a sample content passed to cssJsLoader
const style = {
color: '#eee',
fontWeight: 'thin',
fontSize: 24,
textAlign: 'center',
padding: 18,
};
// Bind functions to global to replicate `this`
global.cssJsLoader = jest.fn(cssJsLoader);
global.cacheable = jest.fn();
global.exec = jest.fn((x) => x);
// Mock a module
jest.mock('loader-utils', () => {
return {
getLoaderConfig: jest.fn(),
};
});
describe('css-js-loader:', () => {
it('Blank style is not modified', () => {
expect(global.cssJsLoader({})).toMatchSnapshot();
});
it('Basic javascript style is converted', () => {
expect(global.cssJsLoader(style)).toMatchSnapshot();
});
it('An array of javascript styles are converted', () => {
expect(global.cssJsLoader([style])).toMatchSnapshot();
});
it('es6 style objects are converted', () => {
const sampleObject = {TITLE: style};
// Make the object pass the es6 check
Object.defineProperty(sampleObject, '__esModule', {
value: true,
});
expect(global.cssJsLoader(sampleObject)).toMatchSnapshot();
});
it('Stringified class names are converted', () => {
const stringedClassName = {
'.blueText': style,
};
expect(global.cssJsLoader(stringedClassName)).toMatchSnapshot();
});
it('Style url attributes are maintained', () => {
const styleWithUrl = {
'background-image': "url('http://example.com/bg.jpg')",
...style,
};
expect(global.cssJsLoader(styleWithUrl)).toMatchSnapshot();
});
});