TestBed.overrideComponent doesn't work with AOT and webpack

Đang mở
#32,628 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
angular, typescript
Lĩnh vực
build-system, testing-qa

Hướng nghiên cứu

Bắt đầu với bản tái hiện tối thiểu: một bài kiểm thử component sử dụng TestBed.overrideComponent hoặc TestBed.overrideModule với Karma, webpack builder ở browser mode và bật AOT. So sánh lỗi với application builder mode hoặc khi tắt AOT, sau đó xác minh rằng bài kiểm thử override chạy mà không gặp lỗi thiếu metadata @Component trong cấu hình bị ảnh hưởng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area: @angular-devkit/build-angular devkit/build-angular:karma freq1: low severity3: broken type: bug/fix
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

TestBed.overrideComponent and TestBed.overrideModule don't seem to work with karma, webpack builder (builderMode: browser) and aot enabled. Changing any of these settings, so builderMode: application or disabling aot "fixes" the problem. The same issue was reported here https://github.com/angular/angular-cli/issues/30017 but i guess it was only fixed for esbuild? Is there any workaround for this? or can it be fixed for angular20?

Minimal Reproduction

Create a simple valid component, turn on AOT for Karma, and make a test where you use TestBed.overrideComponent to reset metadata. You don't even need to specify an actual override in the second parameter to trigger the issue: TestBed.overrideComponent(YourComponent, {}) triggers the failure.

builderMode: browser needs to be set

Exception or Error
Error: App class doesn't have @Component decorator or is missing metadata.
            at invalidTypeError (node_modules/@angular/core/fesm2022/testing.mjs:1661:12)
            at forEach (node_modules/@angular/core/fesm2022/testing.mjs:1084:23)
            at asyncGeneratorStep (node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1)
            at apply (node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:17:1)
            at _ZoneDelegate.invoke (node_modules/zone.js/fesm2015/zone.js:398:28)
            at ProxyZoneSpec.onInvoke (node_modules/zone.js/fesm2015/zone-testing.js:2132:39)
Your Environment
_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    


Angular CLI: 20.3.18
Node: 22.22.0
Package Manager: npm 10.9.4
OS: win32 x64


Angular: 20.3.17
... common, compiler, compiler-cli, core, forms
... platform-browser, router

Package                         Version
---------------------------------------
@angular-devkit/architect       0.2003.18
@angular-devkit/build-angular   20.3.16
@angular-devkit/core            20.3.18
@angular-devkit/schematics      20.3.18
@angular/build                  20.3.18
@angular/cli                    20.3.18
@schematics/angular             20.3.18
rxjs                            7.8.2
typescript                      5.9.3
zone.js                         0.15.1
Anything else relevant?

No response

Ngôn ngữ chính
TypeScript
Star
27k
Fork
11.8k
Merge trung bình
16 giờ 21 phút
Pull request đã merge (30 ngày)
170

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/angular-cli

Tất cả issue của angular/angular-cli

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.