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

Cannot be tested in Angular unit test #516

Open
eggp opened this issue Jul 20, 2021 · 2 comments
Open

Cannot be tested in Angular unit test #516

eggp opened this issue Jul 20, 2021 · 2 comments

Comments

@eggp
Copy link

eggp commented Jul 20, 2021

Describe the bug
Masks created in Angular cannot be tested via the NativeInputElemet value property or input event either. A simple reactive form cannot be tested if it has a mask, because although the value is displayed in the form control, the value is not displayed in the value property in HTMLInputElement, but the values are displayed in a running application.

To Reproduce
Test repository: https://github.com/eggp/angular-imask-unit-test

Runned app:
image

  1. The image shows a field with the following mask: { mask: '{+1(}000{)}000{-}0000', lazy: false } (https://github.com/eggp/angular-imask-unit-test/blob/master/src/app/app.component.ts#L11).

In the Console we wrote the native input element value property and it looks like the values are included in it perfectly.

  1. The attached repository includes three types of tests [with karma]: native jasmine, cdk harness, ngneat / spectator. I tried out the extra frameworks because they handle the change detector pretty well. I thought there was a mistake in mismanaging the change detector in the test, but unfortunately that is not true.

  2. In tests I only managed to get a positive result if I patched formControl, but I would like to be able to test the field by writing from an html input page, as if the user were writing ...

Native jasmine test: https://github.com/eggp/angular-imask-unit-test/blob/master/src/app/app.component.native.spec.ts

CDK Harness test: https://github.com/eggp/angular-imask-unit-test/blob/master/src/app/app.component.harness.spec.ts

ngneat/spectator test: https://github.com/eggp/angular-imask-unit-test/blob/master/src/app/app.component.spectator.spec.ts

Angular version: 11.2.14

Expected behavior
I want the value of HTMLInputElement.value to load well during the test. Or I want to ask for guidance on how to test the inputs properly.

Environment:

  • OS: all
  • Browser: all
  • Version: -
  • IMask version: 6.1.0
  • Framework/plugin version if used: angular-imask - 6.1.0

Additional context
The error also occurs in the case of jest.

@uNmAnNeR
Copy link
Owner

not sure it's related to imask itself but I hope somebody helps with it.
you can also test Masked model which is not related to view (control) at all but contains same logic as with user interaction.

@irineuruiz
Copy link

We are facing this same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants