Solvedangular cli ng test not working after upgrade to 6.0.0
✔️Accepted Answer
I just ran into this as well (Executed 0 of 0 ERROR
) after upgrading to Angular 6 on a project where tests previously ran successfully. I compared the test.ts
file in my project versus a new project generated with the Angular 6 CLI, and noticed a lot of additional imports (import 'core-js/es7/reflect'
, import 'zone.js/dist/jasmine-patch'
), etc in my project. I replaced these with:
import 'zone.js/dist/zone-testing';
and my tests started executing again. It definitely seems like an error message is getting swallowed somewhere.
Other Answers:
I've done some more investigation. My Karma entrypoint file (which I had renamed from src/test.ts
to ui/main.karma.ts
; all of my .ts files live in ui
rather than src
) does not seem to be getting executed in the way I'd expect: none of the console.error
statements I place in that file ever show up in the console or terminal output (they do show up in the terminal output if I do the same thing in a clean ng new
project.)
I confirmed that my main.karma.ts
file is correctly referenced from the angular.json
test/main option, and I confirmed that compilation fails if I change the "main" attribute to point to a nonexistent filename.
I confirmed that my *.spec.ts
files are detected and included by Karma. The generated _karma_webpack_/main.js
file available when running Karma contains a var map = {...}
line section which maps my spec files to their workspace-relative paths, and the tests themselves show up in that file.
My suspicion is still that something is going wrong with the execution of my Karma main entrypoint file, since like I mentioned, any console.error
or other logging statements I add to that file are not showing up in my terminal output. However, that file is very simple and is identical to the test.ts
provided out-of-the-box by Angular CLI, so I'm still not sure what the issue is.
I've got the same problem. Karma is running but no tests are executed.
It looks like test.ts is not loaded
I got this same issue when using ng upgrade when upgrading to angular 6 on a cli project.
In my situation I had one spec file that silently failed the whole test run. After commenting out this spec, I was able to run tests again.
To find the specific test, I ran ls src/**/*.spec.ts | grep -o ".........$" | cut -d. -f1 | sort | uniq
to get the previous letter before ".spec.ts" part. Then I added these letters. one by one, to regular expression in test.ts file, like a\.spec\.ts
, then (a|b)\.spec\.ts
etc. At the beginning, I run more and more tests successfully, until the regex included corrupted test. For me, the last letter added was 'e', so it was either service or pipe specification.
Subsequently, I was able to find autogenerated service test, that caused the error. I am pretty sure, that the error was in beforeEach part, however I can't figure out the exact reason.
Hope my comment helps someone.
After upgrading the cli the unit tests doesn't start anymore.
Previous behaviour was that the unit tests were found and executed. Now it does not find the unit tests and says 0 of 0 executed.
Versions
Repro steps
Observed behavior