-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.test.js
72 lines (57 loc) · 1.73 KB
/
index.test.js
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
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const config = require('../');
const fs = require('fs');
const stylelint = require('stylelint');
const validCss = fs.readFileSync('./__tests__/valid.css', 'utf-8');
const invalidCss = fs.readFileSync('./__tests__/invalid.css', 'utf-8');
describe('flags no warnings with valid css', () => {
let result;
beforeEach(() => {
result = stylelint.lint({
code: validCss,
config,
});
});
it('did not error', () => {
return result.then((data) => expect(data.errored).toBeFalsy());
});
it('flags no warnings', () => {
return result.then((data) => expect(data.results[0].warnings).toHaveLength(0));
});
});
describe('flags warnings with invalid css', () => {
let result;
beforeEach(() => {
result = stylelint.lint({
code: invalidCss,
config,
});
});
it('did error', () => {
return result.then((data) => expect(data.errored).toBeTruthy());
});
it('flags one warning', () => {
return result.then((data) => expect(data.results[0].warnings).toHaveLength(1));
});
it('correct warning text', () => {
return result.then((data) =>
expect(data.results[0].warnings[0].text).toBe(
'Unexpected unknown type selector "madeup" (selector-type-no-unknown)',
),
);
});
it('correct rule flagged', () => {
return result.then((data) =>
expect(data.results[0].warnings[0].rule).toBe('selector-type-no-unknown'),
);
});
it('correct severity flagged', () => {
return result.then((data) => expect(data.results[0].warnings[0].severity).toBe('error'));
});
it('correct line number', () => {
return result.then((data) => expect(data.results[0].warnings[0].line).toBe(1));
});
it('correct column number', () => {
return result.then((data) => expect(data.results[0].warnings[0].column).toBe(1));
});
});