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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular mounting in component testing weirdly overlaps properties #28658

Closed
PBartrina opened this issue Jan 8, 2024 · 5 comments
Closed

Angular mounting in component testing weirdly overlaps properties #28658

PBartrina opened this issue Jan 8, 2024 · 5 comments
Labels
CT Issue related to component testing npm: @cypress/angular @cypress/angular package issues stage: needs investigating Someone from Cypress needs to look at this stale no activity on this issue for a long period

Comments

@PBartrina
Copy link

PBartrina commented Jan 8, 2024

Current behavior

When I mount and angular component several times, it overrides the previous component but some elements are not reset, for example the @HostBinding classes are added every iteration of the mount without cleaning the previous one.

Desired behavior

I expect either the previous instance is fully removed/cleansed or a new instance is added

Test code to reproduce

  1. Mount an standalone angular component with a property binded to the host. Component example:
@Component({
    selector: 'custom-button',
    template: `<button>This button parent class will change</button>`,
    changeDetection: ChangeDetectionStrategy.OnPush,
    encapsulation: ViewEncapsulation.None,
    standalone: true,
    imports: [NgIf]
})
export class CustomButtomComponent {

    @HostBinding('class')
    @Input()
    buttonType: string = '';
}

Use cy.mount(CustomButtomComponent, { componentProperties: { buttonType: 'class1' } });

  1. Mount the component Again using cy.mount(CustomButtomComponent, { componentProperties: { buttonType: 'class2' } });
  2. Run the test
  3. See the parent div of the component have class="class1 class2"

Cypress Version

13.6.2

Node version

18.18.1

Operating System

macOS 14.2.1

Debug Logs

No response

Other

No response

@Kaemmelot
Copy link

Kaemmelot commented Jan 31, 2024

Just stumbled upon the same problem with Cypress 13.6.4. When using style classes via HostBindings, the mounted root HTML element seems to keep CSS classes from previous test cases.

Edit: I do not use encapsulation: ViewEncapsulation.None as in the example above and the host binding is not an input parameter.

@jordanpowell88
Copy link
Contributor

@PBartrina Are you mounting multiple times per it? If you do so their will be most likely some weird qwerks as even though it will remount the state of TestBed doesn't get reset until the before of the next test.

@PBartrina
Copy link
Author

PBartrina commented Jan 31, 2024

@jordanpowell88 I tried different approaches, but I wasn't mounting several times per it (although I tried it just in case). It happened both mounting in each it separately and using beforeEach.

@jennifer-shehane jennifer-shehane added npm: @cypress/angular @cypress/angular package issues CT Issue related to component testing stage: needs investigating Someone from Cypress needs to look at this labels Feb 26, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Aug 25, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CT Issue related to component testing npm: @cypress/angular @cypress/angular package issues stage: needs investigating Someone from Cypress needs to look at this stale no activity on this issue for a long period
Projects
None yet
Development

No branches or pull requests

5 participants