I looked more at the angular.json file in the working new Angular 15 application. I had to do 2 things:
- remove the "main"
- change the "polyfills"
Changed from:
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
Changed to:
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
Answer from Phil Huhn on Stack Overflow
» npm install karma-jasmine
Will Karma be updated for future versions of Angular and Jasmine?
Should we upgrade Jasmine and Karma related dependencies too during Angular upgrade? - Stack Overflow
Updating the version of Jasmine used in karma-jasmine - Stack Overflow
google chrome - Angular karma can't capture browser after updating angular 9 to 10 - Stack Overflow
I looked more at the angular.json file in the working new Angular 15 application. I had to do 2 things:
- remove the "main"
- change the "polyfills"
Changed from:
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
Changed to:
"options": {
"polyfills": [
"zone.js",
"zone.js/testing"
],
"tsConfig": "tsconfig.spec.json",
Phil Huhn's solution helped me as well. I created a new Angular 16 project and compared it with my own project. Apparently Angular no longer uses the test.ts file.
In addition to Phil's answer, it's worthwhile to note that you can safely remove the test.ts file and any other references to it. I had it listed in tsconfig.spec.json under the files array.
» npm install karma
You can know the jasmine version you are using by running the following Spec:
describe('Test to print out jasmine version', function() {
it('prints jasmine version', function() {
console.log('jasmine-version:');
console.log(jasmine.version || (jasmine.getEnv().versionString && jasmine.getEnv().versionString()));
});
});
and then checking the karma output in your console or browser. It should be something like:
LOG: 'jasmine-version:'
LOG: '2.3.4'
The jasmine library is included in the jasmine-runner plugin as you've already found out. You can find the exact place where this file is loaded in the source code of the plugin: https://github.com/karma-runner/karma-jasmine/blob/master/lib/index.js (line 7)
You can try to modify the plugin so that an upgrade is possible and send a pull request to karma (see http://karma-runner.github.io/0.10/dev/contributing.html)
It a better option to stick to the jasmine version in karma-jasmine and update the whole package. You can use the following command to get the version of all the installed packages:
npm ls
To get the version of the installed global packages:
npm ls -g
To view the latest version available on CDN, use:
npm view karma-jasmine version
Before updating, you can view all versions at the CDN using:
npm view karma-jasmine versions
To install a specific version:
npm install karma-jasmine@~0.2.2
(0.2.2 is the latest available).