Title: Dependency injection and class inheritance doesn't work in Angular 8 library test · Issue #31337 · angular/angular · GitHub
Open Graph Title: Dependency injection and class inheritance doesn't work in Angular 8 library test · Issue #31337 · angular/angular
X Title: Dependency injection and class inheritance doesn't work in Angular 8 library test · Issue #31337 · angular/angular
Description: 🐞 bug report Affected Package The issue is caused by package @angular/core@^8 Is this a regression? Yes, the previous version in which this bug was not present was: @angular/core@7 Description The problem occurs when: The base class has ...
Open Graph Description: 🐞 bug report Affected Package The issue is caused by package @angular/core@^8 Is this a regression? Yes, the previous version in which this bug was not present was: @angular/core@7 Description The ...
X Description: 🐞 bug report Affected Package The issue is caused by package @angular/core@^8 Is this a regression? Yes, the previous version in which this bug was not present was: @angular/core@7 Description The ...
Opengraph URL: https://github.com/angular/angular/issues/31337
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dependency injection and class inheritance doesn't work in Angular 8 library test","articleBody":"# 🐞 bug report\r\n\r\n### Affected Package\r\n\r\nThe issue is caused by package @angular/core@^8\r\n\r\n### Is this a regression?\r\nYes, the previous version in which this bug was not present was: @angular/core@7\r\n\r\n\r\n### Description\r\n\r\nThe problem occurs when:\r\n\r\n1. The base class has a constructor with an injected service. (`Injector` from the example)\r\n\r\n```ts\r\n@Injectable()\r\nexport class BaseService {\r\n // \"Injector\" is just for the sake of example. Any injectable would have the same problem.\r\n constructor(public injector: Injector) {\r\n }\r\n}\r\n```\r\n2. Child class has no constructor (i.e., it relies on base class constructor) AND at least one property with the default value.\r\n\r\n```ts\r\n@Injectable()\r\nexport class MyLibService extends BaseService {\r\n\r\n public foo = 'bar';\r\n\r\n}\r\n```\r\n\r\n3. (_dont ask me how I have found this, but:_) In `angular.json` `[lib name].test.options.codeCoverage` should be true. \r\n\r\n### PROBLEM: \r\n\r\n`injector` is undefined in the instance of `MyLibService`. \r\n\r\n--- \r\n\r\n🚩 Removing property from the child class _(2)_ AND/OR opting out `codeCoverage` config in angular.json _(3)_ doesn't brake test.\r\n\r\nAs a result, I can't have a class inheritance and code coverage at the same time.\r\n\r\n---\r\n\r\nI could put a constructor in the child class and call `super` by passing all required arguments manually, but it's the last option since the real-life scenario is much more complicated than the example provided here.\r\n\r\n## 🔬 Minimal Reproduction\r\ngit repo: https://github.com/ddramone/ng-8-library-inheritance-di-test-bug\r\n\r\nreproduce steps:\r\n\r\n1. Install angular 8 cli\r\n2. Clone `git clone https://github.com/ddramone/ng-8-library-inheritance-di-test-bug.git `\r\n3. `npm i`\r\n4. run Test `ng test my-lib`\r\n\r\n ### Expected behavior\r\n\r\nTest should pass = Injector service should be available in the service instance.","author":{"url":"https://github.com/ip7e","@type":"Person","name":"ip7e"},"datePublished":"2019-06-28T14:16:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":17},"url":"https://github.com/31337/angular/issues/31337"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a0be5036-b18f-3cad-0373-69cd623512c9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A34A:877C4:92E3A6:C9322C:6A6193C5 |
| html-safe-nonce | 1c323fc69615936c1190a4e79085898fed19bc9f27420eea9aadd83ef5738e4a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzRBOjg3N0M0OjkyRTNBNjpDOTMyMkM6NkE2MTkzQzUiLCJ2aXNpdG9yX2lkIjoiMjk0Njc0ODY2OTU0MTU4NTg2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 207a07bd30a8bb405999346109b2a091b567d79ef5564d53ba600c02c6c96da6 |
| hovercard-subject-tag | issue:462056786 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/31337/issue_layout |
| twitter:image | https://opengraph.githubassets.com/567cc2521bf3404f1f4a26f1f11c5f9acca96a33fc397519e6cd5af41f77617d/angular/angular/issues/31337 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/567cc2521bf3404f1f4a26f1f11c5f9acca96a33fc397519e6cd5af41f77617d/angular/angular/issues/31337 |
| og:image:alt | 🐞 bug report Affected Package The issue is caused by package @angular/core@^8 Is this a regression? Yes, the previous version in which this bug was not present was: @angular/core@7 Description The ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ip7e |
| hostname | github.com |
| expected-hostname | github.com |
| None | c28c2f6607f2aacbd934868d997038895c9780d08babfe918550d73773326f4c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cd05235d52ffb3318513d883a56c87a121015c8b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width