Skip to content

Angular Material - Verify Form and Display / Text Value of a Select Box #275

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

Closed
mleimer opened this issue Dec 31, 2021 · 1 comment
Closed

Comments

@mleimer
Copy link
Contributor

mleimer commented Dec 31, 2021

Testing an Angular Material Select-Box https://material.angular.io/components/select/examples#select-custom-trigger appears to be rather cumbersome at this stage.

Based on 04-forms-with-material

..verifying if a Angular Material Select-Box has a pre-set form value requires one to do:
expect((fixture.componentInstance as MaterialFormsComponent).form?.get('color')?.value).toBe('B');

..verifying its pre-set display/text-value requires on to do something like:
detectChanges();
expect(colorControl).toHaveTextContent('Blue');`

It would be great if we could achieve easier solutions where:

  • the value can be verified through toHaveFormValues or toHaveValue on its control
  • any display value / text can be verified without having to click on a native element and forcing detectChanges()

Am I maybe missing something?

@mleimer
Copy link
Contributor Author

mleimer commented Dec 31, 2021

I created this PR here to enhance the example to show how one can currently verify any pre-set values: #276

It would be awesome, if there is an easier solution!

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

No branches or pull requests

1 participant