Skip to content

MatInputHarness.getName() fails with MatInput and ngModel #18624

Closed

Description

@bampakoa

Reproduction

I am trying to get the name of a MatInput control which is bound to a component property name as:
<input matInput [name]="name" [(ngModel)]="model">

I am using the getName() method of MatInputHarness as:

const input = await loader.getHarness(MatInputHarness);
expect(await input.getName()).not.toBe('')

but the expectation fails. If I remove the ngModel directive, the test passes successfully.

https://stackblitz.com/edit/components-issue-atwks1

Expected Behavior

The test should pass

Actual Behavior

The test fails

Environment

  • Angular: 9.0.2
  • CDK/Material: 9.1.0
  • Browser(s):
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Activity

  1. crisbeto commented on Feb 26, 2020

    @crisbeto
    Member

    I looked into it quickly and I managed to reproduce it. It looks like the issue is that when ngModel is set, the native DOM name property isn't being set on the input element.

  2. bampakoa commented on Mar 6, 2020

    @bampakoa
    ContributorAuthor

    @crisbeto if we inspect the element using dev tools it looks like the name property is set correctly to the test value. Or is this the attribute that I see over there?

    image

  3. crisbeto commented on Mar 6, 2020

    @crisbeto
    Member

    Here's what I'm trying. In my case the input doesn't have a name attribute or name property. https://stackblitz.com/edit/angular-gfc66v

  4. bampakoa commented on Mar 6, 2020

    @bampakoa
    ContributorAuthor

    @crisbeto you are right! I inspected the second input of my example that does not have ngModel, sorry about that. So, what do you think? Is this a bug with ngModel?

  5. self-assigned this
    on May 2, 2020
  6. added
    P3
    on May 2, 2020
  7. added a commit that references this issue on May 2, 2020
    f3342aa
  8. added a commit that references this issue on Jun 27, 2020
    13b80a4
  9. added a commit that references this issue on Jul 25, 2020
    ab68ebe
  10. added a commit that references this issue on Nov 18, 2020
    e3652ea
  11. added a commit that references this issue on Apr 18, 2021
    8d0363b
  12. added a commit that references this issue on Jun 19, 2021
    6f35532
  13. added a commit that references this issue on Aug 1, 2021
    155ece6
  14. added a commit that references this issue on Jan 3, 2022
    031f4ce
  15. added 2 commits that reference this issue on Jan 14, 2022
    1926b19
    feac08f
  16. angular-automatic-lock-bot commented on Feb 14, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  17. locked and limited conversation to collaborators on Feb 14, 2022
  18. added a commit that references this issue on Apr 3, 2022
    be5f870
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3area: material/input

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions