Search code examples
angularkarma-jasmine

Angular update from 14 to version 15 and now ng test gets 'No specs found'


I have updated my Angular 14 app to Angular 15.1.4 app. This app was created with Angular 4 and updated to each subsequent version.

'ng serve' builds and launches the app. I ended up deleting .browserslistrc, because of a message when I launch serve and test. Running 'ng test', I get 'No specs found', even though I should have 100's of tests. The tests worked in version 14. The message in the test browser is:

Incomplete: No specs found, , randomized with seed 89005

The message on the command line is:

> ng test
√ Browser application bundle generation complete.
11 02 2023 14:29:13.412:WARN [karma]: No captured browser, open http://localhost:9876/
11 02 2023 14:29:13.429:INFO [karma-server]: Karma v6.4.1 server started at http://localhost:9876/
11 02 2023 14:29:13.430:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
11 02 2023 14:29:13.436:INFO [launcher]: Starting browser Chrome
11 02 2023 14:29:18.071:INFO [Chrome 109.0.0.0 (Windows 10)]: Connected on socket rK2xPAWwWBFkQCuuAAAB with id 43283367
Chrome 109.0.0.0 (Windows 10): Executed 0 of 0 SUCCESS (0.004 secs / 0 secs)
TOTAL: 0 SUCCESS

I'm no expert in the workings of karma. It just works. I compared a newly created version 15 app that test worked, so I removed loading the karma config file in the angular.json file, but still no Specs. I'm not seeing any apparent warnings or errors messages. I'm at a lost of what to do next to get testing to work again.

The GitHub project can be found: https://github.com/PHuhn/Net.Incident4/tree/main/net-incident


Solution

  • I looked more at the angular.json file in the working new Angular 15 application. I had to do 2 things:

    1. remove the "main"
    2. 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",