Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

@HostBinding('attr.id') with dynamic attribute during testing conflicting Karma logic #35215

Open
hodossy opened this issue Feb 7, 2020 · 2 comments
Labels
area: testing Issues related to Angular testing features, such as TestBed freq1: low P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Milestone

Comments

@hodossy
Copy link

hodossy commented Feb 7, 2020

馃悶 bug report

Affected Package

The issue is caused by package @angular/core, @angular/core/testing

Is this a regression?

No

Description

Creating elements that bind to the id attribute of their host from an input causes Karma to display all previously tested elements instead of clearing after each spec.

It seems the issue occurs when the property that is bound is set programmatically during the tests.

馃敩 Minimal Reproduction

https://github.com/hodossy/ng-hostbinding-id-test-issue


npm install
ng test

馃敟 Exception or Error

image

As it can be seen, multiple test elements are left behind, probably because Karma clears the elements by ID.

My expactation would be that Karma removes the previous tested element and only the last one is visible after the test suite is run.

馃實 Your Environment

Angular Version:


Angular CLI: 8.3.25
Node: 10.16.0
OS: win32 x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.25
@angular-devkit/build-angular     0.803.25
@angular-devkit/build-optimizer   0.803.25
@angular-devkit/build-webpack     0.803.25
@angular-devkit/core              8.3.25
@angular-devkit/schematics        8.3.25
@angular/cli                      8.3.25
@ngtools/webpack                  8.3.25
@schematics/angular               8.3.25
@schematics/update                0.803.25
rxjs                              6.4.0
typescript                        3.5.3
webpack                           4.39.2

Anything else relevant?
I had no time to test with other browsers than Chrome, but I think it should not be specific to Chrome

@pkozlowski-opensource pkozlowski-opensource added area: core Issues related to the framework runtime area: testing Issues related to Angular testing features, such as TestBed labels Feb 7, 2020
@ngbot ngbot bot modified the milestone: needsTriage Feb 7, 2020
@hodossy hodossy changed the title @HostBinding('attr.id') with dynamic attribute during testing confilcting Karma logic @HostBinding('attr.id') with dynamic attribute during testing conflicting Karma logic Feb 10, 2020
@flemgs
Copy link

flemgs commented Feb 28, 2020

I am facing the same issue here.

@pkozlowski-opensource pkozlowski-opensource added freq1: low severity3: broken type: bug/fix and removed area: core Issues related to the framework runtime labels Feb 28, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Feb 28, 2020
@jelbourn jelbourn added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed severity3: broken labels Oct 1, 2020
@andy-bond
Copy link

I ran into this issue as well except I am using Jest & Angular Testing Library.

I worked around it by using a "wrapper" element to be rendered - rather than directly rendering the Component under test.

I believe this issue is occurring because of this line in TestBed that is setting the ID of the component under test to be used in teardown later.


For those using Angular Testing Library, the change on my end was pretty simple.

Instead of doing this:

await render(MyComponentUnderTest, { 
  excludeComponentDeclaration: true,
  imports: [MyComponentModule] 
})

I instead do this which automatically creates a "wrapper" around the component under test:

await render('<my-component-under-test></my-component-under-test>', { 
  imports: [MyComponentModule] 
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: testing Issues related to Angular testing features, such as TestBed freq1: low P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent type: bug/fix
Projects
None yet
Development

No branches or pull requests

5 participants