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

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

Closed
bampakoa opened this issue Feb 26, 2020 · 5 comments · Fixed by #19233
Closed

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

bampakoa opened this issue Feb 26, 2020 · 5 comments · Fixed by #19233
Assignees
Labels
area: material/input P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@bampakoa
Copy link
Contributor

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
@crisbeto
Copy link
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.

@bampakoa
Copy link
Contributor Author

bampakoa commented Mar 6, 2020

@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

@crisbeto
Copy link
Member

crisbeto commented Mar 6, 2020

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

@bampakoa
Copy link
Contributor Author

bampakoa commented Mar 6, 2020

@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?

@crisbeto crisbeto self-assigned this May 2, 2020
@crisbeto crisbeto added has pr P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels May 2, 2020
crisbeto added a commit to crisbeto/material2 that referenced this issue May 2, 2020
If an input has a `name` binding and an `ngModel`, the input harness won't be able to read the name from the DOM, because `ngModel` doesn't proxy it. These changes add the proxy behavior to the `MatInput` directive, similarly to what we we're doing for `required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 27, 2020
If an input has a `name` binding and an `ngModel`, the input harness won't be able to read the name from the DOM, because `ngModel` doesn't proxy it. These changes add the proxy behavior to the `MatInput` directive, similarly to what we we're doing for `required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 25, 2020
If an input has a `name` binding and an `ngModel`, the input harness won't be able to read the name from the DOM, because `ngModel` doesn't proxy it. These changes add the proxy behavior to the `MatInput` directive, similarly to what we we're doing for `required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
crisbeto added a commit to crisbeto/material2 that referenced this issue Nov 18, 2020
If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
crisbeto added a commit to crisbeto/material2 that referenced this issue Apr 18, 2021
If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jun 19, 2021
If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 1, 2021
If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
crisbeto added a commit to crisbeto/material2 that referenced this issue Jan 3, 2022
If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
andrewseguin pushed a commit that referenced this issue Jan 14, 2022
…del (#19233)

If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes #18624.
andrewseguin pushed a commit that referenced this issue Jan 14, 2022
…del (#19233)

If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes #18624.

(cherry picked from commit 1926b19)
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 14, 2022
forsti0506 pushed a commit to forsti0506/components that referenced this issue Apr 3, 2022
…del (angular#19233)

If an input has a `name` binding and an `ngModel`, the input harness won't be able to
read the name from the DOM, because `ngModel` doesn't proxy it. These changes add
the proxy behavior to the `MatInput` directive, similarly to what we we're doing for
`required`, `placeholder`, `readonly` etc.

Fixes angular#18624.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/input P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants