@@ -50,16 +50,39 @@ describe(ruleName, () => {
50
50
}
51
51
` ;
52
52
53
- it ( `should fail when explicitly call ${ lifecycleHookMethod } ` , ( ) => {
53
+ it ( `should fail when explicitly calling ${ lifecycleHookMethodCall } ` , ( ) => {
54
54
assertAnnotated ( {
55
55
ruleName,
56
- message : ` Avoid explicitly calls to lifecycle hooks in class " ${ className } "` ,
56
+ message : ' Avoid explicit calls to lifecycle hooks.' ,
57
57
source
58
58
} ) ;
59
59
} ) ;
60
60
} ) ;
61
61
} ) ;
62
62
}
63
+
64
+ lifecycleHooksMethods . forEach ( lifecycleHookMethod => {
65
+ const lifecycleHookMethodCall = `fixture.componentInstance.${ lifecycleHookMethod } ()` ;
66
+ const totalTildes = '~' . repeat ( lifecycleHookMethodCall . length ) ;
67
+ const source = `
68
+ it('should work', () => {
69
+ // test code...
70
+
71
+ ${ lifecycleHookMethodCall }
72
+ ${ totalTildes }
73
+
74
+ // more test code...
75
+ })
76
+ ` ;
77
+
78
+ it ( `should fail when explicitly calling ${ lifecycleHookMethod } outside of a class` , ( ) => {
79
+ assertAnnotated ( {
80
+ ruleName,
81
+ message : `Avoid explicit calls to lifecycle hooks.` ,
82
+ source
83
+ } ) ;
84
+ } ) ;
85
+ } ) ;
63
86
} ) ;
64
87
65
88
describe ( 'success' , ( ) => {
@@ -77,7 +100,28 @@ describe(ruleName, () => {
77
100
}
78
101
` ;
79
102
80
- it ( `should pass when call ${ fakeMethod } method` , ( ) => {
103
+ it ( `should pass when calling ${ fakeMethod } method` , ( ) => {
104
+ assertSuccess ( ruleName , source ) ;
105
+ } ) ;
106
+ } ) ;
107
+ } ) ;
108
+ }
109
+
110
+ // call super lifecycle hook
111
+ for ( const metadataKey of metadataKeys ) {
112
+ describe ( metadataKey , ( ) => {
113
+ metadataPairs [ metadataKey ] . forEach ( lifecycleHookMethod => {
114
+ const lifecycleHookMethodCall = `super.${ lifecycleHookMethod } ()` ;
115
+ const source = `
116
+ @${ metadataKey } ()
117
+ class ${ className } implements ${ lifecycleHookMethod . slice ( 2 ) } {
118
+ ${ lifecycleHookMethod } () {
119
+ ${ lifecycleHookMethodCall }
120
+ }
121
+ }
122
+ ` ;
123
+
124
+ it ( `should pass when explicitly calling ${ lifecycleHookMethodCall } ` , ( ) => {
81
125
assertSuccess ( ruleName , source ) ;
82
126
} ) ;
83
127
} ) ;
0 commit comments