diff --git a/README.md b/README.md index 88f738a7..10bcc0a3 100644 --- a/README.md +++ b/README.md @@ -1186,15 +1186,17 @@ describe('AuthService', () => { }); ``` -When using the component schematic you can specify the `--jest` flag to have the Jest imports used. In order to Jest imports the default, update `angular.json`: +When using the component schematic you can specify the `--unitTestRunner` flag to `jest` to have the Jest imports used. In order to Jest imports the default, update `angular.json`: ```json "schematics": { "@ngneat/spectator:spectator-component": { - "jest": true + "unitTestRunner": "jest" } } ``` +Please note that the previous `--jest` flag is deprecated and will be removed in the future. + ## Vitest Support Like Jest, Spectator also supports Vitest. @@ -1246,6 +1248,15 @@ describe('AuthService', () => { }); ``` +When using the component schematic you can specify the `--unitTestRunner` flag to `vitest` to have the Vitest imports used. In order to Vitest imports the default, update `angular.json`: +```json +"schematics": { + "@ngneat/spectator:spectator-component": { + "unitTestRunner": "vitest" + } +} +``` + ## Testing with HTTP Spectator makes testing data services, which use the Angular HTTP module, a lot easier. For example, let's say that you have service with three methods, one performs a GET, one a POST and one performs concurrent requests: diff --git a/projects/spectator/schematics/src/spectator/component-schema.json b/projects/spectator/schematics/src/spectator/component-schema.json index fd6fc617..ac221395 100644 --- a/projects/spectator/schematics/src/spectator/component-schema.json +++ b/projects/spectator/schematics/src/spectator/component-schema.json @@ -126,7 +126,15 @@ "jest": { "type": "boolean", "default": false, - "description": "When true, uses Jest to create mocks." + "description": "When true, uses Jest to create mocks. Deprecated: use unitTestRunner instead.", + "deprecated": true + }, + "unitTestRunner": { + "type": "string", + "enum": ["jasmine", "jest", "vitest"], + "description": "Test runner to use to create mocks.", + "default": "jasmine", + "alias": "u" } }, "required": [ diff --git a/projects/spectator/schematics/src/spectator/directive-schema.json b/projects/spectator/schematics/src/spectator/directive-schema.json index 4861d866..58bfc100 100644 --- a/projects/spectator/schematics/src/spectator/directive-schema.json +++ b/projects/spectator/schematics/src/spectator/directive-schema.json @@ -74,7 +74,15 @@ "jest": { "type": "boolean", "default": false, - "description": "When true, uses Jest to create mocks." + "description": "When true, uses Jest to create mocks. Deprecated: use unitTestRunner instead.", + "deprecated": true + }, + "unitTestRunner": { + "type": "string", + "enum": ["jasmine", "jest", "vitest"], + "description": "Test runner to use to create mocks.", + "default": "jasmine", + "alias": "u" } }, "required": [ diff --git a/projects/spectator/schematics/src/spectator/files/component-custom-host/__name@dasherize__.__type@dasherize__.spec.ts b/projects/spectator/schematics/src/spectator/files/component-custom-host/__name@dasherize__.__type@dasherize__.spec.ts index f1043ee4..7ce6944d 100644 --- a/projects/spectator/schematics/src/spectator/files/component-custom-host/__name@dasherize__.__type@dasherize__.spec.ts +++ b/projects/spectator/schematics/src/spectator/files/component-custom-host/__name@dasherize__.__type@dasherize__.spec.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; -import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>'; +import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>'; import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component'; diff --git a/projects/spectator/schematics/src/spectator/files/component-host/__name@dasherize__.__type@dasherize__.spec.ts b/projects/spectator/schematics/src/spectator/files/component-host/__name@dasherize__.__type@dasherize__.spec.ts index a0993147..a0815220 100644 --- a/projects/spectator/schematics/src/spectator/files/component-host/__name@dasherize__.__type@dasherize__.spec.ts +++ b/projects/spectator/schematics/src/spectator/files/component-host/__name@dasherize__.__type@dasherize__.spec.ts @@ -1,4 +1,4 @@ -import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>'; +import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>'; import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component'; diff --git a/projects/spectator/schematics/src/spectator/files/component/__name@dasherize__.__type@dasherize__.spec.ts b/projects/spectator/schematics/src/spectator/files/component/__name@dasherize__.__type@dasherize__.spec.ts index d0df9d45..db27381a 100644 --- a/projects/spectator/schematics/src/spectator/files/component/__name@dasherize__.__type@dasherize__.spec.ts +++ b/projects/spectator/schematics/src/spectator/files/component/__name@dasherize__.__type@dasherize__.spec.ts @@ -1,4 +1,4 @@ -import { Spectator, createComponentFactory } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>'; +import { Spectator, createComponentFactory } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>'; import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component'; diff --git a/projects/spectator/schematics/src/spectator/files/data-service/__name@dasherize__.service.spec.ts b/projects/spectator/schematics/src/spectator/files/data-service/__name@dasherize__.service.spec.ts index e4c71149..e87e24e0 100644 --- a/projects/spectator/schematics/src/spectator/files/data-service/__name@dasherize__.service.spec.ts +++ b/projects/spectator/schematics/src/spectator/files/data-service/__name@dasherize__.service.spec.ts @@ -1,4 +1,4 @@ -import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator'; +import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>'; import { <%= classify(name)%>Service } from './<%= dasherize(name)%>.service'; describe('<%= classify(name)%>Service', () => { diff --git a/projects/spectator/schematics/src/spectator/files/directive/__name@dasherize__.directive.spec.ts b/projects/spectator/schematics/src/spectator/files/directive/__name@dasherize__.directive.spec.ts index 9be3a170..8562315d 100644 --- a/projects/spectator/schematics/src/spectator/files/directive/__name@dasherize__.directive.spec.ts +++ b/projects/spectator/schematics/src/spectator/files/directive/__name@dasherize__.directive.spec.ts @@ -1,4 +1,4 @@ -import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>'; +import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>'; import { <%= classify(name)%>Directive } from './<%= dasherize(name)%>.directive'; diff --git a/projects/spectator/schematics/src/spectator/files/pipe/__name@dasherize__.pipe.spec.ts b/projects/spectator/schematics/src/spectator/files/pipe/__name@dasherize__.pipe.spec.ts index a696723d..8b005773 100644 --- a/projects/spectator/schematics/src/spectator/files/pipe/__name@dasherize__.pipe.spec.ts +++ b/projects/spectator/schematics/src/spectator/files/pipe/__name@dasherize__.pipe.spec.ts @@ -1,4 +1,4 @@ -import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>'; +import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>'; import { <%= classify(name)%>Pipe } from './<%= dasherize(name)%>.pipe'; diff --git a/projects/spectator/schematics/src/spectator/files/service/__name@dasherize__.service.spec.ts b/projects/spectator/schematics/src/spectator/files/service/__name@dasherize__.service.spec.ts index f855c813..06f63279 100644 --- a/projects/spectator/schematics/src/spectator/files/service/__name@dasherize__.service.spec.ts +++ b/projects/spectator/schematics/src/spectator/files/service/__name@dasherize__.service.spec.ts @@ -1,4 +1,4 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>'; +import { createServiceFactory, SpectatorService } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>'; import { <%= classify(name)%>Service } from './<%= dasherize(name)%>.service'; describe('<%= classify(name)%>Service', () => { @@ -10,4 +10,4 @@ describe('<%= classify(name)%>Service', () => { it('should...', () => { expect(spectator.service).toBeTruthy(); }); -}); \ No newline at end of file +}); diff --git a/projects/spectator/schematics/src/spectator/index.js b/projects/spectator/schematics/src/spectator/index.js index c0f996df..5907edbb 100644 --- a/projects/spectator/schematics/src/spectator/index.js +++ b/projects/spectator/schematics/src/spectator/index.js @@ -11,7 +11,7 @@ const parse_name_1 = require("@schematics/angular/utility/parse-name"); function spectatorComponentSchematic(options) { return (0, schematics_1.chain)([ (0, schematics_1.externalSchematic)('@schematics/angular', 'component', { - ...omit(options, ['jest', 'withHost', 'withCustomHost']), + ...omit(options, ['jest', 'withHost', 'withCustomHost', 'unitTestRunner']), skipTests: true, }), async (tree, _context) => { @@ -24,6 +24,7 @@ function spectatorComponentSchematic(options) { (0, schematics_1.template)({ ...core_1.strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), (0, schematics_1.move)(movePath), ]); @@ -34,7 +35,7 @@ function spectatorComponentSchematic(options) { function spectatorServiceSchematic(options) { return (0, schematics_1.chain)([ (0, schematics_1.externalSchematic)('@schematics/angular', 'service', { - ...omit(options, ['jest', 'isDataService']), + ...omit(options, ['jest', 'isDataService', 'unitTestRunner']), skipTests: true, }), async (tree, _context) => { @@ -47,6 +48,7 @@ function spectatorServiceSchematic(options) { (0, schematics_1.template)({ ...core_1.strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), (0, schematics_1.move)(movePath), ]); @@ -57,7 +59,7 @@ function spectatorServiceSchematic(options) { function spectatorDirectiveSchematic(options) { return (0, schematics_1.chain)([ (0, schematics_1.externalSchematic)('@schematics/angular', 'directive', { - ...omit(options, ['jest']), + ...omit(options, ['jest', 'unitTestRunner']), skipTests: true, }), async (tree, _context) => { @@ -70,6 +72,7 @@ function spectatorDirectiveSchematic(options) { (0, schematics_1.template)({ ...core_1.strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), (0, schematics_1.move)(movePath), ]); @@ -80,7 +83,7 @@ function spectatorDirectiveSchematic(options) { function spectatorPipeSchematic(options) { return (0, schematics_1.chain)([ (0, schematics_1.externalSchematic)('@schematics/angular', 'pipe', { - ...omit(options, ['jest']), + ...omit(options, ['jest', 'unitTestRunner']), skipTests: true, }), async (tree, _context) => { @@ -93,6 +96,7 @@ function spectatorPipeSchematic(options) { (0, schematics_1.template)({ ...core_1.strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), (0, schematics_1.move)(movePath), ]); @@ -121,4 +125,16 @@ function omit(original, keys) { return obj; }, {}); } +function getSecondaryEntryPoint(options) { + const secondaryEntryPoints = { + jest: 'jest', + vitest: 'vitest', + jasmine: null, + }; + if (options.jest) { + console.warn('The `jest` option is deprecated and will be removed in the future. Use `unitTestRunner` instead.'); + return secondaryEntryPoints.jest; + } + return secondaryEntryPoints[options.unitTestRunner]; +} //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/projects/spectator/schematics/src/spectator/index.js.map b/projects/spectator/schematics/src/spectator/index.js.map index a9597388..89f2815a 100644 --- a/projects/spectator/schematics/src/spectator/index.js.map +++ b/projects/spectator/schematics/src/spectator/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAoBA,kEA4BC;AAED,8DAwBC;AAED,kEAwBC;AAED,wDAwBC;AA9HD,+CAA0D;AAC1D,2DAaoC;AACpC,qEAAuF;AACvF,uEAAmE;AAInE,SAAgB,2BAA2B,CAAC,OAAyB;IACnE,OAAO,IAAA,kBAAK,EAAC;QACX,IAAA,8BAAiB,EAAC,qBAAqB,EAAE,WAAW,EAAE;YACpD,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;YACxD,SAAS,EAAE,IAAI;SAChB,CAAC;QACF,KAAK,EAAE,IAAU,EAAE,QAA0B,EAAiB,EAAE;YAC9D,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBACtB,OAAO,iBAAI,CAAC;YACd,CAAC;YAED,MAAM,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAE,OAAO,CAAC,IAAe,CAAC,CAAC,CAAC,IAAA,gBAAS,EAAC,OAAO,CAAC,IAAI,GAAG,GAAG,GAAG,cAAO,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAEjI,MAAM,gBAAgB,GAAG,IAAA,kBAAK,EAC5B,IAA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AO,CAAC,IAAI,GAAG,IAAA,4BAAgB,EAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,UAAU,GAAG,IAAA,sBAAS,EAAC,OAAO,CAAC,IAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACnE,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAC/B,OAAO,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;AACjC,CAAC;AAED,SAAS,IAAI,CAAqC,QAAW,EAAE,IAAiB;IAC9E,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;SACzB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SACpC,MAAM,CAAC,CAAC,GAA6B,EAAE,GAAG,EAAE,EAAE;QAC7C,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEzB,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC;AAED,SAAS,sBAAsB,CAAC,OAA2D;IACzF,MAAM,oBAAoB,GAA0C;QAClE,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,QAAQ;QAChB,OAAO,EAAE,IAAI;KACd,CAAC;IACF,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,kGAAkG,CAAC,CAAC;QACjH,OAAO,oBAAoB,CAAC,IAAI,CAAC;IACnC,CAAC;IACD,OAAO,oBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AACtD,CAAC"} \ No newline at end of file diff --git a/projects/spectator/schematics/src/spectator/index.ts b/projects/spectator/schematics/src/spectator/index.ts index a5bacb44..60ae36bf 100644 --- a/projects/spectator/schematics/src/spectator/index.ts +++ b/projects/spectator/schematics/src/spectator/index.ts @@ -16,12 +16,12 @@ import { import { buildDefaultPath, getWorkspace } from '@schematics/angular/utility/workspace'; import { parseName } from '@schematics/angular/utility/parse-name'; -import { ComponentOptions, DirectiveOptions, ServiceOptions } from './schema'; +import { ComponentOptions, DirectiveOptions, PipeOptions, ServiceOptions, UnitTestRunner } from './schema'; export function spectatorComponentSchematic(options: ComponentOptions): Rule { return chain([ externalSchematic('@schematics/angular', 'component', { - ...omit(options, ['jest', 'withHost', 'withCustomHost']), + ...omit(options, ['jest', 'withHost', 'withCustomHost', 'unitTestRunner']), skipTests: true, }), async (tree: Tree, _context: SchematicContext): Promise => { @@ -38,6 +38,7 @@ export function spectatorComponentSchematic(options: ComponentOptions): Rule { template({ ...strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), move(movePath), ], @@ -51,7 +52,7 @@ export function spectatorComponentSchematic(options: ComponentOptions): Rule { export function spectatorServiceSchematic(options: ServiceOptions): Rule { return chain([ externalSchematic('@schematics/angular', 'service', { - ...omit(options, ['jest', 'isDataService']), + ...omit(options, ['jest', 'isDataService', 'unitTestRunner']), skipTests: true, }), async (tree: Tree, _context: SchematicContext): Promise => { @@ -65,6 +66,7 @@ export function spectatorServiceSchematic(options: ServiceOptions): Rule { template({ ...strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), move(movePath), ]); @@ -77,7 +79,7 @@ export function spectatorServiceSchematic(options: ServiceOptions): Rule { export function spectatorDirectiveSchematic(options: DirectiveOptions): Rule { return chain([ externalSchematic('@schematics/angular', 'directive', { - ...omit(options, ['jest']), + ...omit(options, ['jest', 'unitTestRunner']), skipTests: true, }), async (tree: Tree, _context: SchematicContext): Promise => { @@ -91,6 +93,7 @@ export function spectatorDirectiveSchematic(options: DirectiveOptions): Rule { template({ ...strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), move(movePath), ]); @@ -100,10 +103,10 @@ export function spectatorDirectiveSchematic(options: DirectiveOptions): Rule { ]); } -export function spectatorPipeSchematic(options: DirectiveOptions): Rule { +export function spectatorPipeSchematic(options: PipeOptions): Rule { return chain([ externalSchematic('@schematics/angular', 'pipe', { - ...omit(options, ['jest']), + ...omit(options, ['jest', 'unitTestRunner']), skipTests: true, }), async (tree: Tree, _context: SchematicContext): Promise => { @@ -117,6 +120,7 @@ export function spectatorPipeSchematic(options: DirectiveOptions): Rule { template({ ...strings, ...options, + secondaryEntryPoint: getSecondaryEntryPoint(options), }), move(movePath), ]); @@ -153,3 +157,16 @@ function omit>(original: T, keys: (keyof T)[] return obj; }, {}); } + +function getSecondaryEntryPoint(options: { jest?: boolean; unitTestRunner: UnitTestRunner }): string | null { + const secondaryEntryPoints: Record = { + jest: 'jest', + vitest: 'vitest', + jasmine: null, + }; + if (options.jest) { + console.warn('The `jest` option is deprecated and will be removed in the future. Use `unitTestRunner` instead.'); + return secondaryEntryPoints.jest; + } + return secondaryEntryPoints[options.unitTestRunner]; +} diff --git a/projects/spectator/schematics/src/spectator/pipe-schema.json b/projects/spectator/schematics/src/spectator/pipe-schema.json index b1a6e9ae..540d9c39 100644 --- a/projects/spectator/schematics/src/spectator/pipe-schema.json +++ b/projects/spectator/schematics/src/spectator/pipe-schema.json @@ -55,7 +55,15 @@ "jest": { "type": "boolean", "default": false, - "description": "When true, uses Jest to create mocks." + "description": "When true, uses Jest to create mocks. Deprecated: use unitTestRunner instead.", + "deprecated": true + }, + "unitTestRunner": { + "type": "string", + "enum": ["jasmine", "jest", "vitest"], + "description": "Test runner to use to create mocks.", + "default": "jasmine", + "alias": "u" } }, "required": [ diff --git a/projects/spectator/schematics/src/spectator/schema.js.map b/projects/spectator/schematics/src/spectator/schema.js.map index afdaaee1..40535d23 100644 --- a/projects/spectator/schematics/src/spectator/schema.js.map +++ b/projects/spectator/schematics/src/spectator/schema.js.map @@ -1 +1 @@ -{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":";;;AAEA,MAAa,gBAAgB;CAyD5B;AAzDD,4CAyDC;AACD,MAAa,cAAc;CAgB1B;AAhBD,wCAgBC;AACD,MAAa,gBAAgB;CAmC5B;AAnCD,4CAmCC;AACD,MAAa,WAAW;CAgCvB;AAhCD,kCAgCC"} \ No newline at end of file +{"version":3,"file":"schema.js","sourceRoot":"","sources":["schema.ts"],"names":[],"mappings":";;;AAIA,MAAa,gBAAgB;CA8D5B;AA9DD,4CA8DC;AACD,MAAa,cAAc;CAqB1B;AArBD,wCAqBC;AACD,MAAa,gBAAgB;CAwC5B;AAxCD,4CAwCC;AACD,MAAa,WAAW;CAoCvB;AApCD,kCAoCC"} \ No newline at end of file diff --git a/projects/spectator/schematics/src/spectator/schema.ts b/projects/spectator/schematics/src/spectator/schema.ts index 922e0a03..f2e015ea 100644 --- a/projects/spectator/schematics/src/spectator/schema.ts +++ b/projects/spectator/schematics/src/spectator/schema.ts @@ -1,5 +1,7 @@ import { ChangeDetection, ViewEncapsulation } from '@angular/cli/lib/config/workspace-schema'; +export type UnitTestRunner = 'jasmine' | 'jest' | 'vitest'; + export class ComponentOptions { name: string; path?: string; @@ -54,9 +56,14 @@ export class ComponentOptions { */ viewEncapsulation?: ViewEncapsulation; /** + * @deprecated * Specifies if Jest is to be used for mocking */ jest?: boolean; + /** + * Specifies the unit test runner to use + */ + unitTestRunner: UnitTestRunner; } export class ServiceOptions { name: string; @@ -71,9 +78,14 @@ export class ServiceOptions { */ skipTests?: boolean; /** + * @deprecated * Specifies if a spec file is generated. */ jest?: boolean; + /** + * Specifies the unit test runner to use + */ + unitTestRunner: UnitTestRunner; } export class DirectiveOptions { name: string; @@ -107,9 +119,14 @@ export class DirectiveOptions { */ skipTests?: boolean; /** + * @deprecated * Specifies if Jest is to be used for mocking */ jest?: boolean; + /** + * Specifies the unit test runner to use + */ + unitTestRunner: UnitTestRunner; } export class PipeOptions { name: string; @@ -135,10 +152,14 @@ export class PipeOptions { */ skipTests?: boolean; /** + * @deprecated * Specifies if Jest is to be used for mocking */ jest?: boolean; - + /** + * Specifies the unit test runner to use + */ + unitTestRunner: UnitTestRunner; /** * Adds a developer-defined type to the filename, in the format "name.type.ts" */ diff --git a/projects/spectator/schematics/src/spectator/service-schema.json b/projects/spectator/schematics/src/spectator/service-schema.json index a9ca11e4..ab78740e 100644 --- a/projects/spectator/schematics/src/spectator/service-schema.json +++ b/projects/spectator/schematics/src/spectator/service-schema.json @@ -45,7 +45,15 @@ "jest": { "type": "boolean", "default": false, - "description": "When true, uses Jest to create mocks." + "description": "When true, uses Jest to create mocks. Deprecated: use unitTestRunner instead.", + "deprecated": true + }, + "unitTestRunner": { + "type": "string", + "enum": ["jasmine", "jest", "vitest"], + "description": "Test runner to use to create mocks.", + "default": "jasmine", + "alias": "u" } }, "required": [