Angular-cli test coverage all files

前端 未结 6 1216
灰色年华
灰色年华 2021-02-07 09:16

I am running the following command to unit test and generate code code coverage report.

ng test --code-coverage

It is writing code coverage re

6条回答
  •  被撕碎了的回忆
    2021-02-07 10:06

    I had the same issue and I found a simple workaround that does the trick for me without any big configuration.

    1. In your app folder, create a file app.module.spec.ts
    2. In this file add an import to your app module.

    import './app.module';

    That's it ;)

    The point is, your app module is most likely the central part of your application which imports any other used files directly or indirectly. Now that you have created the spec file, everything that is included by your module should also be included in the test coverage report.

    I am not 100% sure if this works with lazy loaded modules. If not, you can simply import those lazy loaded modules in your app.module.spec.ts as well, or create a spec file per module, where you import the module.

提交回复
热议问题