Select and Option component not working with tests in Karma
See original GitHub issueBug :
Select component from Angular Material don’t load Option components in Karma
What is the expected behavior?
Using Karma & testbed, I should be able to fetch Option components related to my Select component instance
What is the current behavior?
Only the Select is displayed, and if I fetch for Options, I find nothing. The same in Karma preview : if I click on the Select, nothing happens (i.e. no option is shown)
What are the steps to reproduce?
- Create a new CLI project
- Install and import angular material
- In the app.component.html file, add a Select components with options, such as :
<md-select placeholder="Favorite food"> <md-option [value]="1">1</md-option> <md-option [value]="2">2</md-option> <md-option [value]="3">3</md-option> </md-select>
- Launch Karma (ng test command) and see that there is nothing inside the Select component instance
What is the use-case or motivation for changing an existing behavior?
Allow us to unit test our pages using Select components
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
"@angular/animations": "^4.1.3",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/material": "^2.0.0-beta.6",
Is there anything else we should know?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Angular click select option in component test - Stack Overflow
I was able to get the value that is now selected by doing selectEl.innerText.trim() . Not sure if this is the best way...
Read more >ng test - Angular
Option Description Value Type Defau...
‑‑browsers Override which browsers tests are run against. string
‑‑code‑coverage Output a code coverage report. boolean false
‑‑code‑coverage‑exclude Globs to exclude...
Read more >Front-End Unit Testing Using Karma Test Runner
This tutorial explains how to setup Karma & automate Front-End Unit Testing Using Karma, basic configuration options for Karma.conf.js file ...
Read more >Angular Test Select Dropdown - ConcretePage.com
This page will walk through Angular unit test select dropdown example. In our component we have two select elements and their property ...
Read more >Configuration File - Karma
If false, Karma does not clear the context window upon the completion of running the tests. Setting this to false is useful when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Took us a bit of time working through the specs suggested above to get this working for our use case - we put together a helper class to deal with some of the bolierplate around select menu testing which may be helpful to others - https://gist.github.com/glendaviesnz/fc8e99b41f0dda8b1c0dc4d397e0d152
@YoannBureau the unit tests that @jelbourn pointed to should be sufficient. You may be particularly interested in this section.