Actually you need not just create a spy but also execute it to increase coverage. A spy replaces the spied function with a stub. If you want this spy function to be called normally, you need to add .and.callThrough() to your spy.

spyOn(EnvironmentService, 'isProduction').and.callThrough()

You can also read more here: about spy and callThrough

Answer from Tatsiana on Stack Overflow
๐ŸŒ
Angular Minds
angularminds.com โ€บ blog โ€บ methods-to-increase-code-coverage-in-angular
Methods to Increase Code Coverage in Angular
October 3, 2024 - Libraries like jest or Angularโ€™s HttpClientTestingModule can help you create mock services and APIs, ensuring that tests focus solely on the componentโ€™s logic. ... Include edge cases in your tests to ensure that your application handles unexpected or extreme conditions gracefully. ... Ensure that all branches of conditional statements (e.g., if, switch) are executed. Write tests that cover each possible path. ... Leverage code coverage tools like Istanbul (via nyc) or coverage with Karma to identify untested branches.
๐ŸŒ
Angular
angular.dev โ€บ guide โ€บ testing โ€บ code-coverage
Code coverage โ€ข Angular
If you want to create code-coverage reports every time you test, you can set the coverage option to true in your angular.json file:
Discussions

Not able to increase code coverage in Angular Unit testing - Stack Overflow
I am new to angular unit testing and I dont know how to test methods properly so as to get code coverage. More on stackoverflow.com
๐ŸŒ stackoverflow.com
angular - How do I get hundred percent code coverage with my unit testing on this component and access the else part? - Stack Overflow
I have no idea how to access the remaining line of code. I simply need to get a full code coverage. Checking if the function has been called (toHaveBeenCalled() ) will also do. Pasting in the TypeS... More on stackoverflow.com
๐ŸŒ stackoverflow.com
angular - How to increase code coverage to 80 percentage in Jasmine test case - Stack Overflow
I have written completed writing HTML, TS and service for angular components. I now have started writing test cases..but I cannot reach 80 percentage. Can someone please help how to reach till 80 More on stackoverflow.com
๐ŸŒ stackoverflow.com
angular5 - How to implement code coverage for angular 5? - Stack Overflow
Please provide the steps for code coverage report for angular 5? More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Coryrylan
coryrylan.com โ€บ blog โ€บ enforcing-code-coverage-in-angular-cli-projects
Enforcing Code Coverage in Angular CLI Projects - Angular 17 | 16
November 24, 2023 - Learn how to set up minimum code coverage rules for unit testing in an Angular CLI project.
๐ŸŒ
Medium
diegoperezsalas.medium.com โ€บ how-to-write-a-jest-test-with-100-coverage-in-angular-27cfbda9a445
How to Achieve 100% Code Coverage with Jest Tests in Angular | by Diego Perez Salas | Medium
March 26, 2024 - In conclusion, achieving 100% code coverage with unit tests in Angular using Jest requires a thorough and comprehensive testing strategy. Unit tests should focus on testing the behavior and functionality of individual components, services, and ...
๐ŸŒ
Compile N Run
compilenrun.com โ€บ angular tutorial โ€บ angular testing โ€บ angular code coverage
Angular Code Coverage | Compile N Run
Use it as part of a broader testing strategy that includes different types of tests and focuses on building reliable, maintainable applications. ... Run code coverage on an existing Angular project and identify areas with low coverage.
๐ŸŒ
Testing-angular
testing-angular.com โ€บ measuring-code-coverage
Measuring code coverage โ€“ Testing Angular
February 17, 2021 - New features should include tests, bug fixes should include a test as proof and to prevent regressions. ... Writing new code and changing existing code should not lower the coverage score, but gradually increase it.
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to achieve Code Coverage in Angular Unit Testing | Conclusion | Angular Unit Testing Made Easy - YouTube
How to achieve Code Coverage in Angular Unit Testing | Conclusion | Angular Unit Testing Made EasyIn this comprehensive tutorial, we dive deep into code cove...
Published ย  January 9, 2023
๐ŸŒ
DEV Community
dev.to โ€บ alisaduncan โ€บ how-to-level-up-your-angular-unit-testing-game-23-ged
How To Level Up Your Angular Unit Testing Game (2/3) - DEV Community
January 22, 2019 - It has an "options" property. Add a new property for "codeCoverage" and set the value to true. You can set more properties than just coverage. All parameters that you pass in to Angular CLI can be configured.
๐ŸŒ
Daniel Kreider
danielk.tech โ€บ home โ€บ angular-code-coverage
Angular Code Coverage (How to measure and use) | Daniel Kreider
December 9, 2024 - Today we're going to show you how to set up code coverage in your Angular project.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ angular_cli โ€บ angular_cli_code_coverage.htm
Angular CLI - Code Coverage
This chapter will discuss the Angular CLI Code Coverage, including a detailed introduction, syntax, usage, and an example that shows how to use it in an Angular application. In Angular development, the CLI provides a metric (standard of measurement)
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 64147421 โ€บ how-do-i-get-hundred-percent-code-coverage-with-my-unit-testing-on-this-componen
angular - How do I get hundred percent code coverage with my unit testing on this component and access the else part? - Stack Overflow
So I assumed you were trying to create an expired token to get into the else part. To do that you just need an expired token. ... The tricky part here is that the code you need to test is in a callback function (accept()) that, in a normal runtime scenario, would be invoked by the ConfirmationService (presumably when a user clicks a button).
๐ŸŒ
Andrewhalil
andrewhalil.com โ€บ 2021 โ€บ 11 โ€บ 02 โ€บ test-code-coverage-within-angular-applications
Test Code Coverage in an Angular Application โ€“ andrewhalil.com
November 2, 2021 - Welcome to todayโ€™s post. Today I will be showing you how to use test coverage within an Angular application. And it is, believe me, one of the most useful features that comes with the Angular development environment. In many posts previously I have given overviews of unit testing within not ...
๐ŸŒ
Daniel Kreider
danielk.tech โ€บ home โ€บ how-to-set-up-angular-code-coverage-in-vs-code
How to set up Angular code coverage in VS Code | Daniel Kreider
Go to Extensions in VS Code, search for Coverage Gutters and install it. Once installed, you'll see green lines to show what part of your Angular code is being tested.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 68088539 โ€บ how-to-increase-code-coverage-to-80-percentage-in-jasmine-test-case
angular - How to increase code coverage to 80 percentage in Jasmine test case - Stack Overflow
Can someone please help how to reach till 80 percentage. Also, is there some tool which can help me determine what cases I have missed? ... In the root of your application, there should be a coverage folder.
๐ŸŒ
Medium
shashankvivek-7.medium.com โ€บ taking-code-coverage-to-newer-heights-with-ease-angular-karma-vs-code-3a8ba81d4d8c
Taking Code Coverage to Newer Heights with Ease โ€” Angular + VS Code Plugin | by Shashank Vivek | Medium
September 27, 2022 - If you are new to to Angular โ€” ... task to monitor code coverage is fairly simplified by creating coverage folder which contains coverage results as lcov.info file....