Title: `TestBed.overrideComponent` breaks module imports with `@angular/build:unit-test` · Issue #33064 · angular/angular-cli · GitHub
Open Graph Title: `TestBed.overrideComponent` breaks module imports with `@angular/build:unit-test` · Issue #33064 · angular/angular-cli
X Title: `TestBed.overrideComponent` breaks module imports with `@angular/build:unit-test` · Issue #33064 · angular/angular-cli
Description: Command test Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description Reopening from angular/angular#68363 as I don't feel it was ful...
Open Graph Description: Command test Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description Reopening from angular/...
X Description: Command test Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description Reopening from angular/...
Opengraph URL: https://github.com/angular/angular-cli/issues/33064
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`TestBed.overrideComponent` breaks module imports with `@angular/build:unit-test`","articleBody":"### Command\n\ntest\n\n### Is this a regression?\n\n- [ ] Yes, this behavior used to work in the previous version\n\n### The previous version in which this bug was not present was\n\n_No response_\n\n### Description\n\nReopening from https://github.com/angular/angular/issues/68363 as I don't feel it was fully answered and I later found the issue is related to the new builder.\n\nWhen using the `@angular/build:unit-test` builder, `TestBed.overrideComponent` breaks imports out of modules. This happens for both vitest and karma runners, so I would assume it is connected to the build, not the test execution.\n\nThe issue does not occur when using other builder like `@angular-devkit/build-angular:karma`\n\n### Minimal Reproduction\n\nPlain Angular project + packages needed for running karma\n\n```typescript\n// app.spec.ts\nimport { Component, NgModule } from '@angular/core';\nimport { TestBed } from '@angular/core/testing';\n\n@Component({\n selector: 'test-component',\n template: '',\n})\nexport class TestComponent {}\n\n@NgModule({\n imports: [TestComponent],\n exports: [TestComponent],\n})\nexport class TestModule {}\n\n@Component({\n selector: 'app-root',\n imports: [TestModule],\n template: ` \u003ctest-component>\u003c/test-component> `,\n})\nexport class App {}\n\ndescribe('App', () => {\n beforeEach(async () => {\n await TestBed.configureTestingModule({\n imports: [App],\n })\n .overrideComponent(App, {}) // \u003c= problematic call\n .compileComponents();\n });\n\n it('should create', () => {\n expect(TestBed.createComponent(App)).toBeTruthy();\n });\n});\n```\n\n```jsonc\n// angular.json\n...\n// fails\n\"test-vitest\": {\n \"builder\": \"@angular/build:unit-test\",\n \"options\": {\n \"runner\": \"vitest\"\n }\n},\n// fails\n\"test-karma\": {\n \"builder\": \"@angular/build:unit-test\",\n \"options\": {\n \"runner\": \"karma\"\n }\n},\n// this one works\n\"test-karma-devkit\": {\n \"builder\": \"@angular-devkit/build-angular:karma\",\n \"options\": {\n \"tsConfig\": \"./tsconfig.spec.json\"\n }\n}\n...\n```\n\nRunning the test with `@angular/build:unit-test` it fails for both runners with\n```\nError: NG0304: 'test-component' is not a known element (used in the '_App' component template):\n1. If 'test-component' is an Angular component, then verify that it is included in the '@Component.imports' of this component.\n2. If 'test-component' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@Component.schemas' of this component to suppress this message.\n ❯ validateElementIsKnown ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/element_validation.ts:116:14\n ❯ validateElementIsKnown ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/element.ts:151:4\n ❯ initializeElement ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/element.ts:127:2\n ❯ ɵɵelementStart ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/element.ts:218:2\n ❯ _App_Template ng:/_App.js:6:21\n ❯ templateFn ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/shared.ts:109:4\n ❯ executeTemplate ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/render.ts:107:6\n ❯ renderView ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/render.ts:47:4\n ❯ renderComponent ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/render.ts:160:4\n ❯ renderChildComponents ../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/packages/core/src/render3/instructions/render.ts:140:6\n```\n\nWith the `@angular-devkit/build-angular:karma` it passes as expected.\n\nAlso actually overriding something in `TestBed.overrideComponent` doesn't change the behaviour. I originally discovered this with a test that needs to stub a component. I left it out for simplicity here.\n\n### Exception or Error\n\n```text\n\n```\n\n### Your Environment\n\n```text\n_ _ ____ _ ___\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\n / △ \\ | '_ \\ / _` | | | | |/ _` | '__| | | | | | |\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\n /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\n |___/\n\n\nAngular CLI : 21.2.8\nAngular : 21.2.10\nNode.js : 24.15.0\nPackage Manager : npm 10.9.4\nOperating System : win32 x64\n\n┌───────────────────────────────┬───────────────────┬───────────────────┐\n│ Package │ Installed Version │ Requested Version │\n├───────────────────────────────┼───────────────────┼───────────────────┤\n│ @angular-devkit/build-angular │ 21.2.8 │ ^21.2.8 │\n│ @angular/build │ 21.2.8 │ ^21.2.7 │\n│ @angular/cli │ 21.2.8 │ ^21.2.7 │\n│ @angular/common │ 21.2.10 │ ^21.2.0 │\n│ @angular/compiler │ 21.2.10 │ ^21.2.0 │\n│ @angular/compiler-cli │ 21.2.10 │ ^21.2.0 │\n│ @angular/core │ 21.2.10 │ ^21.2.0 │\n│ @angular/forms │ 21.2.10 │ ^21.2.0 │\n│ @angular/platform-browser │ 21.2.10 │ ^21.2.0 │\n│ @angular/router │ 21.2.10 │ ^21.2.0 │\n│ rxjs │ 7.8.2 │ ~7.8.0 │\n│ typescript │ 5.9.3 │ ~5.9.2 │\n│ vitest │ 4.1.5 │ ^4.0.8 │\n└───────────────────────────────┴───────────────────┴───────────────────┘\n```\n\n### Anything else relevant?\n\n_No response_","author":{"url":"https://github.com/m-yst-ery","@type":"Person","name":"m-yst-ery"},"datePublished":"2026-04-28T08:08:08Z","url":"https://github.com/angular/angular-cli/issues/33064"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:15105354-85ae-d96d-5108-1cbb8e03dfd0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8850:1AE20C:36431CD:44BB92E:6B01DE71 |
| html-safe-nonce | cb98c8770a7aa805ea52e954af73a47f104711bc604ccc2fd26630a0c9b130b8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4ODUwOjFBRTIwQzozNjQzMUNEOjQ0QkI5MkU6NkIwMURFNzEiLCJ2aXNpdG9yX2lkIjoiODI1NzIzMjU5Mjk1NzQ2NDE3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 54bf6ededae63185a7501f92ddfbbc59c2aa74f73a112137d1c228682ecefa32 |
| hovercard-subject-tag | issue:4341555354 |
| 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-cli/33064/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53d0c5a1ca7d01cd6367dbe795339244918f504fadd45585d9af07cb4eb9fe2e/angular/angular-cli/issues/33064 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53d0c5a1ca7d01cd6367dbe795339244918f504fadd45585d9af07cb4eb9fe2e/angular/angular-cli/issues/33064 |
| og:image:alt | Command test Is this a regression? Yes, this behavior used to work in the previous version The previous version in which this bug was not present was No response Description Reopening from angular/... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | m-yst-ery |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width