Skip to content

Commit f0d651a

Browse files
committed
feat: 🎸 upgrade to Angular v20
npx ng update @angular/core @angular/cli @angular/cdk angular-eslint @angular-builders/jest @analogjs/vitest-angular @analogjs/vite-plugin-angular jest-preset-angular prettier BREAKING CHANGE: 🧨 removed TestBed.get support
1 parent 694e97c commit f0d651a

File tree

10 files changed

+1513
-4072
lines changed

10 files changed

+1513
-4072
lines changed

angular.json

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"prefix": "lib",
1111
"architect": {
1212
"build": {
13-
"builder": "@angular-devkit/build-angular:ng-packagr",
13+
"builder": "@angular/build:ng-packagr",
1414
"options": {
1515
"tsConfig": "projects/spectator/tsconfig.lib.json",
1616
"project": "projects/spectator/ng-package.json"
@@ -22,7 +22,7 @@
2222
}
2323
},
2424
"test": {
25-
"builder": "@angular-devkit/build-angular:karma",
25+
"builder": "@angular/build:karma",
2626
"options": {
2727
"tsConfig": "projects/spectator/tsconfig.spec.json",
2828
"karmaConfig": "projects/spectator/karma.conf.js",
@@ -68,6 +68,30 @@
6868
},
6969
"@angular-eslint/schematics:library": {
7070
"setParserOptionsProject": true
71+
},
72+
"@schematics/angular:component": {
73+
"type": "component"
74+
},
75+
"@schematics/angular:directive": {
76+
"type": "directive"
77+
},
78+
"@schematics/angular:service": {
79+
"type": "service"
80+
},
81+
"@schematics/angular:guard": {
82+
"typeSeparator": "."
83+
},
84+
"@schematics/angular:interceptor": {
85+
"typeSeparator": "."
86+
},
87+
"@schematics/angular:module": {
88+
"typeSeparator": "."
89+
},
90+
"@schematics/angular:pipe": {
91+
"typeSeparator": "."
92+
},
93+
"@schematics/angular:resolver": {
94+
"typeSeparator": "."
7195
}
7296
}
7397
}

package.json

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,23 @@
3131
"release:dry": "cd projects/spectator && standard-version --infile ../../CHANGELOG.md --dry-run"
3232
},
3333
"devDependencies": {
34-
"@analogjs/vite-plugin-angular": "^1.10.1",
35-
"@analogjs/vitest-angular": "^1.10.1",
36-
"@angular-builders/jest": "^18.0.0",
37-
"@angular-devkit/build-angular": "^19.0.1",
38-
"@angular-devkit/schematics": "^19.0.1",
39-
"@angular/animations": "^19.0.0",
40-
"@angular/build": "^19.0.0",
41-
"@angular/cdk": "^19.0.0",
42-
"@angular/cli": "^19.0.1",
43-
"@angular/common": "^19.0.0",
44-
"@angular/compiler": "^19.0.0",
45-
"@angular/compiler-cli": "^19.0.0",
46-
"@angular/core": "^19.0.0",
47-
"@angular/forms": "^19.0.0",
48-
"@angular/language-service": "^19.0.0",
49-
"@angular/platform-browser": "^19.0.0",
50-
"@angular/platform-browser-dynamic": "^19.0.0",
51-
"@angular/router": "19.0.0",
34+
"@analogjs/vite-plugin-angular": "^1.18.0",
35+
"@analogjs/vitest-angular": "^1.18.0",
36+
"@angular-builders/jest": "^19.0.1",
37+
"@angular-devkit/schematics": "^20.0.1",
38+
"@angular/animations": "^20.0.2",
39+
"@angular/build": "^20.0.1",
40+
"@angular/cdk": "^20.0.2",
41+
"@angular/cli": "^20.0.1",
42+
"@angular/common": "^20.0.2",
43+
"@angular/compiler": "^20.0.2",
44+
"@angular/compiler-cli": "^20.0.2",
45+
"@angular/core": "^20.0.2",
46+
"@angular/forms": "^20.0.2",
47+
"@angular/language-service": "^20.0.2",
48+
"@angular/platform-browser": "^20.0.2",
49+
"@angular/platform-browser-dynamic": "^20.0.2",
50+
"@angular/router": "20.0.2",
5251
"@commitlint/cli": "17.3.0",
5352
"@commitlint/config-angular": "17.3.0",
5453
"@commitlint/config-conventional": "17.3.0",
@@ -58,7 +57,7 @@
5857
"@typescript-eslint/eslint-plugin": "^8.33.1",
5958
"@typescript-eslint/parser": "^8.33.1",
6059
"all-contributors-cli": "^6.19.0",
61-
"angular-eslint": "^19.8.0",
60+
"angular-eslint": "^20.1.1",
6261
"core-js": "^3.9.1",
6362
"cross-env": "^5.1.4",
6463
"cz-conventional-changelog": "^3.3.0",
@@ -69,24 +68,24 @@
6968
"jasmine-core": "5.1.1",
7069
"jasmine-spec-reporter": "7.0.0",
7170
"jest": "29.7.0",
72-
"jest-preset-angular": "14.1.0",
71+
"jest-preset-angular": "14.6.0",
7372
"jsdom": "^25.0.1",
7473
"karma": "6.4.2",
7574
"karma-chrome-launcher": "3.2.0",
7675
"karma-coverage-istanbul-reporter": "3.0.3",
7776
"karma-jasmine": "5.1.0",
7877
"karma-jasmine-html-reporter": "2.1.0",
7978
"lint-staged": "^13.1.0",
80-
"ng-packagr": "19.0.1",
81-
"prettier": "3.2.5",
79+
"ng-packagr": "20.0.0",
80+
"prettier": "3.5.3",
8281
"rxjs": "7.8.1",
8382
"standard-version": "^9.1.0",
8483
"ts-node": "10.1.0",
8584
"tslib": "^2.6.2",
86-
"typescript": "5.6.3",
85+
"typescript": "5.8.3",
8786
"typescript-eslint": "^8.33.1",
8887
"vite-tsconfig-paths": "^5.0.1",
89-
"vitest": "2.1.8",
88+
"vitest": "3.2.2",
9089
"zone.js": "0.15.0"
9190
},
9291
"config": {

projects/spectator/src/lib/base/base-spectator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Token } from '../token';
88
*/
99
export abstract class BaseSpectator {
1010
public inject<T>(token: Token<T>): SpyObject<T> {
11-
return TestBed.inject ? TestBed.inject(token) : TestBed.get(token);
11+
return TestBed.inject(token) as SpyObject<T>;
1212
}
1313

1414
/**

projects/spectator/src/lib/internals/query.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { By } from '@angular/platform-browser';
33

44
import { DOMSelector } from '../dom-selectors';
55
import { isString, QueryOptions, QueryType } from '../types';
6+
import { type Token } from '../token';
67

78
export function getChildren<R>(debugElementRoot: DebugElement): (directiveOrSelector: QueryType, options?: QueryOptions<R>) => R[] {
89
return (directiveOrSelector: QueryType, options: QueryOptions<R> = { root: false, read: undefined }): R[] => {
@@ -15,7 +16,7 @@ export function getChildren<R>(debugElementRoot: DebugElement): (directiveOrSele
1516
);
1617

1718
if (options.read) {
18-
return debugElements.map((debug) => debug.injector.get(options.read));
19+
return debugElements.map((debug) => debug.injector.get(options.read as Token<R>));
1920
}
2021

2122
if (isString(directiveOrSelector)) {

projects/spectator/src/lib/spectator-http/create-factory.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ export function createHttpFactory<S>(typeOrOptions: Type<S> | SpectatorHttpOptio
3535
});
3636

3737
afterEach(() => {
38-
if (TestBed.inject) {
39-
TestBed.inject(HttpTestingController).verify();
40-
} else {
41-
TestBed.get(HttpTestingController).verify();
42-
}
38+
TestBed.inject(HttpTestingController).verify();
4339
});
4440

4541
return (overrides?: CreateHttpOverrides<S>) => {
@@ -52,13 +48,6 @@ export function createHttpFactory<S>(typeOrOptions: Type<S> | SpectatorHttpOptio
5248
});
5349
}
5450

55-
/**
56-
* Back compatibility, angular under 9 version doesnt have a inject function
57-
*/
58-
if (!TestBed.inject) {
59-
return new SpectatorHttp<S>(TestBed.get(service), TestBed.get(HttpClient), TestBed.get(HttpTestingController));
60-
}
61-
6251
return new SpectatorHttp<S>(TestBed.inject(service), TestBed.inject(HttpClient), TestBed.inject(HttpTestingController));
6352
};
6453
}

projects/spectator/src/lib/spectator-routing/create-factory.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export function createRoutingFactory<C>(typeOrOptions: Type<C> | SpectatorRoutin
7474
TestBed.overrideProvider(ActivatedRoute, {
7575
useValue: new ActivatedRouteStub({ params, queryParams, data, fragment, url, root, parent, children, firstChild }),
7676
});
77-
const ngZone = (<any>TestBed).inject ? TestBed.inject(NgZone) : TestBed.get(NgZone);
77+
78+
const ngZone = TestBed.inject(NgZone);
7879

7980
return ngZone.run(() => {
8081
const spectator = createSpectatorRouting(options, props);
@@ -96,13 +97,6 @@ function createSpectatorRouting<C>(options: Required<SpectatorRoutingOptions<C>>
9697

9798
const component = setProps(fixture.componentRef, props);
9899

99-
/**
100-
* Back compatibility, angular under 9 version doesnt have a inject function
101-
*/
102-
if (!TestBed.inject) {
103-
return new SpectatorRouting(fixture, debugElement, component, TestBed.get(Router), TestBed.get(ActivatedRoute));
104-
}
105-
106100
return new SpectatorRouting(
107101
fixture,
108102
debugElement,

projects/spectator/src/lib/spectator-service/create-factory.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ export function createServiceFactory<S>(typeOrOptions: Type<S> | SpectatorServic
3434
});
3535

3636
afterEach(() => {
37-
const testedService = (<any>TestBed).inject
38-
? (<{ inject<T>(token: Type<T>, notFoundValue?: T): T } & TestBedStatic>TestBed).inject<S>(service)
39-
: TestBed.get(service);
37+
const testedService = (<{ inject<T>(token: Type<T>, notFoundValue?: T): T } & TestBedStatic>TestBed).inject<S>(service) as object;
4038

4139
if (doesServiceImplementsOnDestroy(testedService)) {
42-
// eslint-disable-next-line
4340
testedService.ngOnDestroy();
4441
}
4542
});
@@ -54,6 +51,6 @@ export function createServiceFactory<S>(typeOrOptions: Type<S> | SpectatorServic
5451
});
5552
}
5653

57-
return new SpectatorService<S>(TestBed.inject ? TestBed.inject(service) : TestBed.get(service));
54+
return new SpectatorService<S>(TestBed.inject(service));
5855
};
5956
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InjectionToken, AbstractType, Type } from '@angular/core';
1+
import { InjectionToken, AbstractType, Type, ProviderToken } from '@angular/core';
22

33
/** Type representing valid typesafe token types for provider binding. */
4-
export type Token<T> = Type<T> | InjectionToken<T> | AbstractType<T>;
4+
export type Token<T> = Type<T> | InjectionToken<T> | AbstractType<T> | ProviderToken<T>;

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"sourceMap": true,
77
"declaration": false,
88
"module": "es2020",
9-
"moduleResolution": "node",
9+
"moduleResolution": "bundler",
1010
"emitDecoratorMetadata": true,
1111
"experimentalDecorators": true,
1212
"importHelpers": true,
@@ -35,7 +35,9 @@
3535
"projects/spectator/internals/src/public_api.ts"
3636
],
3737
// workaround for: https://github.com/rollup/rollup/issues/5199
38-
"rollup/parseAst": ["./node_modules/rollup/dist/parseAst"]
38+
"rollup/parseAst": [
39+
"./node_modules/rollup/dist/parseAst"
40+
]
3941
},
4042
"useDefineForClassFields": false
4143
}

0 commit comments

Comments
 (0)