/
noOutputRenameRule.spec.ts
79 lines (73 loc) · 2.25 KB
/
noOutputRenameRule.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
import { getFailureMessage, Rule } from '../src/noOutputRenameRule';
import { assertAnnotated, assertSuccess } from './testHelper';
const {
metadata: { ruleName }
} = Rule;
describe(ruleName, () => {
describe('failure', () => {
it('should fail when a directive output property is renamed', () => {
const source = `
@Component({
template: 'test'
})
class TestComponent {
@Output('onChange') change = new EventEmitter<void>();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
`;
assertAnnotated({
message: getFailureMessage(),
ruleName,
source
});
});
it('should fail when a directive output property is renamed and its name is strictly equal to the property', () => {
const source = `
@Component({
template: 'test'
})
class TestComponent {
@Output('change') change = new EventEmitter<void>();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
`;
assertAnnotated({ message: getFailureMessage(), ruleName, source });
});
it("should fail when the directive's selector matches exactly both property name and the alias", () => {
const source = `
@Directive({
selector: '[test], foo'
})
class TestDirective {
@Output('test') test = new EventEmitter<void>();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
`;
assertAnnotated({ message: getFailureMessage(), ruleName, source });
});
});
describe('success', () => {
it('should succeed when a directive output property is properly used', () => {
const source = `
@Component({
template: 'test'
})
class TestComponent {
@Output() change = new EventEmitter<void>();
}
`;
assertSuccess(ruleName, source);
});
it("should succeed when the directive's selector is also an output property", () => {
const source = `
@Directive({
selector: '[foo], test'
})
class TestDirective {
@Output('foo') bar = new EventEmitter<void>();
}
`;
assertSuccess(ruleName, source);
});
});
});