-
Notifications
You must be signed in to change notification settings - Fork 0
/
blint-react.spec.js
90 lines (75 loc) · 2.85 KB
/
blint-react.spec.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const React = require('react');
const originalCreateElement = React.createElement;
const lint = require('../src/blint-react');
describe('blint-react', () => {
beforeEach(() => {
jasmine.addMatchers({
toPassBlint() {
return {
compare: function(className){
var pass = false;
var stack = '';
try {
lint(className);
pass = true
} catch(e) { stack = e.stack }
var result = { pass };
if(pass) {
result.message = `Expected className '${className}' to pass the blint linter. ${stack}`;
} else {
result.message = `Expected className '${className}' to pass the blint linter. ${stack}`;
}
return result;
}
}
}
})
});
it('should monkey-patch React.createElement', () => {
expect(React.createElement).not.toBe(originalCreateElement);
});
it('should fail linter when there are classes from more than one Module', () => {
expect('FooModule FooOtherModule').not.toPassBlint();
expect('FooModule BamBam-foo').not.toPassBlint();
expect('FooModule Grammy-doo-mooMoo').not.toPassBlint();
expect('One-uno Two-dos').not.toPassBlint();
});
it('should fail linter when there are multiple elements', () => {
expect('Foo-one Foo-two').not.toPassBlint();
});
it('should fail linter when there is a module and an element', () => {
expect('Foo Foo-two').not.toPassBlint();
});
it('should fail linter when there is a module modifier and an element', () => {
expect('Foo--bar Foo-two').not.toPassBlint();
});
it('should fail linter when there is an element modifier without an element', () => {
expect('Foo-bar--baz').not.toPassBlint();
});
it('should fail linter when there is an element modifier and a module modifier', () => {
expect('Foo--bar Foo-bar--baz').not.toPassBlint();
});
it('should fail linter when there is a module modifier but no module', () => {
expect('Foo--bar').not.toPassBlint();
});
it('should fail linter when there is an element modifier but no element', () => {
expect('Foo-bar--baz').not.toPassBlint();
});
it('should fail linter when class naming is incorrect', () => {
expect('Foo-One').not.toPassBlint();
expect('Foo-one--Two').not.toPassBlint();
expect('Foo-one-two').not.toPassBlint();
expect('FooBar-bar--Baz').not.toPassBlint();
expect('FooBar--Baz').not.toPassBlint();
});
it('should not fail linter when class naming is correct', () => {
expect('Z').toPassBlint();
expect('Z-a Z-a--b').toPassBlint();
expect('Z1-a2 Z1-a2--b3').toPassBlint();
});
it('should not fail linter with valid input', () => {
expect('Foo-one').toPassBlint();
expect('Foo-one Foo-one--twoThree').toPassBlint();
expect('Foo Foo--modifierOk').toPassBlint();
});
});