Skip to content

Commit c924703

Browse files
authored
feat(schematics): introduce unitTestRunner option to support Vitest (#688)
* Added support for vitest as a unit test runner. * Introduced a new unitTestRunner option to specify the test runner (jasmine, jest, vitest). * Deprecated the jest option to avoid redundancy and encourage the use of the new unitTestRunner option.
1 parent 012b6bb commit c924703

17 files changed

+124
-27
lines changed

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -1186,15 +1186,17 @@ describe('AuthService', () => {
11861186
});
11871187
```
11881188

1189-
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`:
1189+
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`:
11901190
```json
11911191
"schematics": {
11921192
"@ngneat/spectator:spectator-component": {
1193-
"jest": true
1193+
"unitTestRunner": "jest"
11941194
}
11951195
}
11961196
```
11971197

1198+
Please note that the previous `--jest` flag is deprecated and will be removed in the future.
1199+
11981200
## Vitest Support
11991201
Like Jest, Spectator also supports Vitest.
12001202

@@ -1246,6 +1248,15 @@ describe('AuthService', () => {
12461248
});
12471249
```
12481250

1251+
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`:
1252+
```json
1253+
"schematics": {
1254+
"@ngneat/spectator:spectator-component": {
1255+
"unitTestRunner": "vitest"
1256+
}
1257+
}
1258+
```
1259+
12491260
## Testing with HTTP
12501261
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
12511262
concurrent requests:

projects/spectator/schematics/src/spectator/component-schema.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@
126126
"jest": {
127127
"type": "boolean",
128128
"default": false,
129-
"description": "When true, uses Jest to create mocks."
129+
"description": "When true, uses Jest to create mocks. Deprecated: use unitTestRunner instead.",
130+
"deprecated": true
131+
},
132+
"unitTestRunner": {
133+
"type": "string",
134+
"enum": ["jasmine", "jest", "vitest"],
135+
"description": "Test runner to use to create mocks.",
136+
"default": "jasmine",
137+
"alias": "u"
130138
}
131139
},
132140
"required": [

projects/spectator/schematics/src/spectator/directive-schema.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@
7474
"jest": {
7575
"type": "boolean",
7676
"default": false,
77-
"description": "When true, uses Jest to create mocks."
77+
"description": "When true, uses Jest to create mocks. Deprecated: use unitTestRunner instead.",
78+
"deprecated": true
79+
},
80+
"unitTestRunner": {
81+
"type": "string",
82+
"enum": ["jasmine", "jest", "vitest"],
83+
"description": "Test runner to use to create mocks.",
84+
"default": "jasmine",
85+
"alias": "u"
7886
}
7987
},
8088
"required": [

projects/spectator/schematics/src/spectator/files/component-custom-host/__name@dasherize__.__type@dasherize__.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component } from '@angular/core';
2-
import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>';
2+
import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>';
33

44
import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component';
55

projects/spectator/schematics/src/spectator/files/component-host/__name@dasherize__.__type@dasherize__.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>';
1+
import { createHostFactory, SpectatorHost } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>';
22

33
import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component';
44

projects/spectator/schematics/src/spectator/files/component/__name@dasherize__.__type@dasherize__.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Spectator, createComponentFactory } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>';
1+
import { Spectator, createComponentFactory } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>';
22

33
import { <%= classify(name)%>Component } from './<%= dasherize(name)%>.component';
44

projects/spectator/schematics/src/spectator/files/data-service/__name@dasherize__.service.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator';
1+
import { createHttpFactory, HttpMethod, SpectatorHttp } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>';
22
import { <%= classify(name)%>Service } from './<%= dasherize(name)%>.service';
33

44
describe('<%= classify(name)%>Service', () => {

projects/spectator/schematics/src/spectator/files/directive/__name@dasherize__.directive.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>';
1+
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>';
22

33
import { <%= classify(name)%>Directive } from './<%= dasherize(name)%>.directive';
44

projects/spectator/schematics/src/spectator/files/pipe/__name@dasherize__.pipe.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>';
1+
import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>';
22

33
import { <%= classify(name)%>Pipe } from './<%= dasherize(name)%>.pipe';
44

projects/spectator/schematics/src/spectator/files/service/__name@dasherize__.service.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createServiceFactory, SpectatorService } from '@ngneat/spectator<% if (jest) { %>/jest<% } %>';
1+
import { createServiceFactory, SpectatorService } from '@ngneat/spectator<% if (secondaryEntryPoint) { %>/<%= secondaryEntryPoint%><% } %>';
22
import { <%= classify(name)%>Service } from './<%= dasherize(name)%>.service';
33

44
describe('<%= classify(name)%>Service', () => {
@@ -10,4 +10,4 @@ describe('<%= classify(name)%>Service', () => {
1010
it('should...', () => {
1111
expect(spectator.service).toBeTruthy();
1212
});
13-
});
13+
});

projects/spectator/schematics/src/spectator/index.js

+20-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/spectator/schematics/src/spectator/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)