Using overrideComponent breaks code coverage when testing with aot: true
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
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- angular, typescript
- Lĩnh vực
- build-system, testing
Hướng nghiên cứu
Tái hiện vấn đề trong ứng dụng được tạo bằng cách sử dụng angular.json, app.spec.ts, TestBed.overrideComponent và các lệnh ng test --no-watch --code-coverage được cung cấp. So sánh mức độ bao phủ trước và sau override, sau đó lần theo các điểm đầu vào của quá trình kiểm thử Angular CLI và mức độ bao phủ AOT. Hoàn tất khi override không còn khiến mức độ bao phủ template của component không chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
When using TestBed.overrideComponent to stub a child component, the test code coverage is no longer accurate
Minimal Reproduction
Generate a new app with latest CLI and add a component:
npx @angular/cli@20.0.0-next.6 new aot-coverage --defaults --no-routing
cd aot-coverage
ng g c user
Use app-user in app.html:
<h1>Hello, aot-coverage</h1>
<app-user></app-user>
Edit angular.json to add "aot": true in the test section and run:
ng test --no-watch --code-coverage
Coverage is 100%
Statements : 100% ( 12/12 )
Branches : 100% ( 11/11 )
Functions : 100% ( 3/3 )
Lines : 100% ( 6/6 )
Now, in the app.spec.ts, add in beforeEach:
TestBed.overrideComponent(App, {
remove: {
imports: [User],
},
add: {
imports: [User],
}
});
(this happens with a proper stub of course but even removing the import and adding it back works to reproduce the issue)
Run the tests again:
ng test --no-watch --code-coverage
Coverage is now inaccurate because the template is not properly covered:
Statements : 58.33% ( 7/12 )
Branches : 90.9% ( 10/11 )
Functions : 66.66% ( 2/3 )
Lines : 66.66% ( 4/6 )
Exception or Error
Your Environment
Angular CLI: 20.0.0-next.6
Node: 22.14.0
Package Manager: npm 10.9.0
OS: darwin arm64
Angular: 20.0.0-next.7
... common, compiler, compiler-cli, core, forms
... platform-browser, router
Package Version
------------------------------------------------------
@angular-devkit/architect 0.2000.0-next.6
@angular-devkit/core 20.0.0-next.6
@angular-devkit/schematics 20.0.0-next.6
@angular/build 20.0.0-next.6
@angular/cli 20.0.0-next.6
@schematics/angular 20.0.0-next.6
rxjs 7.8.2
typescript 5.8.3
zone.js 0.15.0
Anything else relevant?
No response
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 16 giờ 35 phút
- Pull request đã merge (30 ngày)
- 176
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-server Đang mởarea: @angular/build gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
angular/angular-cli#33055 · 1 bình luận · 3 reaction ·
-
unit-test: with --coverage, a setup file's hooks reach only the first spec file of each worker Đang mởarea: @angular/build gemini-triaged
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 người được giao ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 người được giao ·
Tất cả issue của angular/angular-cli
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
ontola/atomic-server#1625 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
melgarafael/DeskcommCRM#1451 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
-
bug via-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bot:ai-assisted component:compact-js status:untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
midnightntwrk/midnight-sdk#403 ·