@@ -102,54 +102,100 @@ describe('AppComponent', () => {
102102 'There should be no uncovered statements as the uncalled function was ignored' ,
103103 ) ;
104104 } ) ;
105- }
106105
107- // Note: V8 does not support 'ignore if' semantic comments; it only supports generic line/block ignores.
108- it ( 'should respect istanbul ignore if comments when computing coverage' , async ( ) => {
109- harness . useTarget ( 'test' , {
110- ...BASE_OPTIONS ,
111- coverage : true ,
112- // eslint-disable-next-line @typescript-eslint/no-explicit-any
113- coverageReporters : [ 'json' ] as any ,
114- } ) ;
106+ it ( `should respect ${ type } ignore if comments when computing coverage` , async ( ) => {
107+ harness . useTarget ( 'test' , {
108+ ...BASE_OPTIONS ,
109+ coverage : true ,
110+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111+ coverageReporters : [ 'json' ] as any ,
112+ } ) ;
115113
116- await harness . writeFile (
117- 'src/app/app.component.ts' ,
118- `
119- import { Component } from '@angular/core';
114+ await harness . writeFile (
115+ 'src/app/app.component.ts' ,
116+ `
117+ import { Component } from '@angular/core';
120118
121- @Component({
122- selector: 'app-root',
123- template: '<h1>hello</h1>',
124- standalone: true,
125- })
126- export class AppComponent {
127- checkValue(val: boolean) {
128- /* istanbul ignore if -- @preserve */
129- if (val) {
130- return true;
119+ @Component({
120+ selector: 'app-root',
121+ template: '<h1>hello</h1>',
122+ standalone: true,
123+ })
124+ export class AppComponent {
125+ checkValue(val: boolean) {
126+ /* ${ type } ignore if -- @preserve */
127+ if (val) {
128+ return true;
129+ }
130+ return false;
131131 }
132- return false;
133132 }
134- }
135- ` ,
136- ) ;
133+ ` ,
134+ ) ;
137135
138- await harness . writeFile (
139- 'src/app/app.component.spec.ts' ,
140- getSpecContent ( `
141- it('should exercise the function but not the if block', () => {
142- const fixture = TestBed.createComponent(AppComponent);
143- const app = fixture.componentInstance;
144- app.checkValue(false);
145- });
146- ` ) ,
147- ) ;
136+ await harness . writeFile (
137+ 'src/app/app.component.spec.ts' ,
138+ getSpecContent ( `
139+ it('should exercise the function but not the if block', () => {
140+ const fixture = TestBed.createComponent(AppComponent);
141+ const app = fixture.componentInstance;
142+ app.checkValue(false);
143+ });
144+ `) ,
145+ ) ;
148146
149- await assertNoUncoveredStatements (
150- 'There should be no uncovered statements as the uncalled branch was ignored' ,
151- ) ;
147+ await assertNoUncoveredStatements (
148+ 'There should be no uncovered statements as the uncalled branch was ignored' ,
149+ ) ;
150+ } ) ;
151+
152+ it ( `should respect ${ type } ignore else comments when computing coverage` , async ( ) => {
153+ harness . useTarget ( 'test' , {
154+ ...BASE_OPTIONS ,
155+ coverage : true ,
156+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
157+ coverageReporters : [ 'json' ] as any ,
158+ } ) ;
159+
160+ await harness . writeFile (
161+ 'src/app/app.component.ts' ,
162+ `
163+ import { Component } from '@angular/core';
164+
165+ @Component({
166+ selector: 'app-root',
167+ template: '<h1>hello</h1>',
168+ standalone: true,
169+ })
170+ export class AppComponent {
171+ checkValue(val: boolean) {
172+ /* ${ type } ignore else -- @preserve */
173+ if (val) {
174+ return true;
175+ } else {
176+ return false;
177+ }
178+ }
179+ }
180+ ` ,
181+ ) ;
182+
183+ await harness . writeFile (
184+ 'src/app/app.component.spec.ts' ,
185+ getSpecContent ( `
186+ it('should exercise the function but not the else block', () => {
187+ const fixture = TestBed.createComponent(AppComponent);
188+ const app = fixture.componentInstance;
189+ app.checkValue(true);
152190 });
191+ ` ) ,
192+ ) ;
193+
194+ await assertNoUncoveredStatements (
195+ 'There should be no uncovered statements as the uncalled else branch was ignored' ,
196+ ) ;
197+ } ) ;
198+ }
153199
154200 it ( 'should respect v8 ignore start/stop comments when computing coverage' , async ( ) => {
155201 harness . useTarget ( 'test' , {
@@ -187,52 +233,5 @@ describe('AppComponent', () => {
187233 'There should be no uncovered statements as the uncalled function was ignored' ,
188234 ) ;
189235 } ) ;
190-
191- it ( 'should respect istanbul ignore else comments when computing coverage' , async ( ) => {
192- harness . useTarget ( 'test' , {
193- ...BASE_OPTIONS ,
194- coverage : true ,
195- // eslint-disable-next-line @typescript-eslint/no-explicit-any
196- coverageReporters : [ 'json' ] as any ,
197- } ) ;
198-
199- await harness . writeFile (
200- 'src/app/app.component.ts' ,
201- `
202- import { Component } from '@angular/core';
203-
204- @Component({
205- selector: 'app-root',
206- template: '<h1>hello</h1>',
207- standalone: true,
208- })
209- export class AppComponent {
210- checkValue(val: boolean) {
211- /* istanbul ignore else -- @preserve */
212- if (val) {
213- return true;
214- } else {
215- return false;
216- }
217- }
218- }
219- ` ,
220- ) ;
221-
222- await harness . writeFile (
223- 'src/app/app.component.spec.ts' ,
224- getSpecContent ( `
225- it('should exercise the function but not the else block', () => {
226- const fixture = TestBed.createComponent(AppComponent);
227- const app = fixture.componentInstance;
228- app.checkValue(true);
229- });
230- ` ) ,
231- ) ;
232-
233- await assertNoUncoveredStatements (
234- 'There should be no uncovered statements as the uncalled else branch was ignored' ,
235- ) ;
236- } ) ;
237236 } ) ;
238237} ) ;
0 commit comments