forked from mgechev/codelyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipePrefixRule.spec.ts
104 lines (96 loc) · 2.65 KB
/
pipePrefixRule.spec.ts
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { assertSuccess, assertAnnotated } from './testHelper';
describe('pipe-prefix', () => {
describe('invalid pipe name', () => {
it('should fail when Pipe has no prefix ng', () => {
let source = `
@Pipe({
name: 'foo-bar'
~~~~~~~~~~~~~~~
})
class Test {}
`;
assertAnnotated({
ruleName: 'pipe-prefix',
message: 'The name of the Pipe decorator of class Test should start with prefix ng, however its value is "foo-bar"',
source,
options: ['ng']
});
});
it('should fail when Pipe has no prefix applying multiple prefixes', () => {
let source = `
@Pipe({
name: 'foo-bar'
~~~~~~~~~~~~~~~
})
class Test {}
`;
assertAnnotated({
ruleName: 'pipe-prefix',
message: 'The name of the Pipe decorator of class Test should start' + ' with prefix ng,mg,sg, however its value is "foo-bar"',
source,
options: ['ng', 'mg', 'sg']
});
});
});
describe('empty pipe', () => {
it('should not fail when @Pipe not invoked', () => {
let source = `
@Pipe
class Test {}
`;
assertSuccess('pipe-prefix', source, ['ng']);
});
});
describe('pipe with name as variable', () => {
it('should ignore the rule when the name is a variable', () => {
const source = `
export function mockPipe(name: string): any {
@Pipe({ name })
class MockPipe implements PipeTransform {
transform(input: any): any {
return input;
}
}
return MockPipe;
}
`;
assertSuccess('pipe-prefix', source, ['ng']);
});
});
describe('valid pipe name', () => {
it('should succeed with prefix ng in @Pipe', () => {
let source = `
@Pipe({
name: 'ngBarFoo'
})
class Test {}
`;
assertSuccess('pipe-prefix', source, ['ng']);
});
it('should succeed with multiple prefixes in @Pipe', () => {
let source = `
@Pipe({
name: 'ngBarFoo'
})
class Test {}
`;
assertSuccess('pipe-prefix', source, ['ng', 'sg', 'mg']);
});
it('should succeed when the class is not a Pipe', () => {
let source = `
class Test {}
`;
assertSuccess('pipe-prefix', source, ['ng']);
});
it('should do nothing if the name of the pipe is not a literal', () => {
let source = `
const pipeName = 'fooBar';
@Pipe({
name: pipeName
})
class Test {}
`;
assertSuccess('pipe-prefix', source, ['ng']);
});
});
});