Open dropdown and Select one of value from dropdown in Angular unit test
See original GitHub issueDescribe the bug I referred to issue no #919 already and tried to implement my test cases based on unit test cases written on official github code. Through unit test case, if you want to open ng-select dropdown and select one of value from dropdown, you can’t select value because ng-option array is always empty.
Reproducbile example
To Reproduce
const selectInput = fixture.debugElement.query(By.css('.ng-select-container'));
let event = new MouseEvent('mousedown', { bubbles: true });
selectInput.nativeElement.dispatchEvent(event);
fixture.detectChanges();
const listItem = fixture.debugElement.query(By.css('.ng-option'));
event = new MouseEvent('click', { bubbles: true });
listItem.nativeElement.dispatchEvent(event);
Issue is for any data passed to ng-select, ng-option array is always empty.
Reason?
Once you debug ng-select.js code, through ngOnInit or ngOnChanges or other method getting with debug, .refresh() method is not getting executed properly and _updateItems() never gets called because _updateItems() method which is emitting items array to viewPortItems attribute of NgSelectComponent.
This viewPortItems is looping array for ng-option which is always empty in case of running Unit test case with any data.
In-depth analysis - Once you debug _handleScroll() and _handleItemsChange() methods, it doesnt execute refresh method code properly somehow.
Expected behavior viewPortItems array should not be empty
Screenshots
Temporary Fix
Checking NgDropDownPanelComponent and emitting value again to Parent Select Component
if (_.isEmpty(ngSelectComponent.viewPortItems)) { // Check for items under NgDropdownPanelComponent
if ( !_.isNil(ngSelectComponent.dropdownPanel) && !_.isEmpty(ngSelectComponent.dropdownPanel.items)) {
ngSelectComponent.dropdownPanel.update.emit(ngSelectComponent.dropdownPanel.items.slice());
}
}
Desktop (please complete the following information):
- Any OS
- Any Browser
- @ng-select/ng-select": “2.14.0”,
Additional context Though I already have implemented or analyzed unit test cases written for this library, Please point to if this questions/issue is answered somewhere.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top GitHub Comments
@varnastadeus Your tests are all lovely to test ng-select itself. But I noticed that you use ViewChild to get a reference to NgSelectComponent and then call open() on it.
How am I supposed to access the NgSelectComponent when it is part of another component? I cannot wrap the component in a test component, since ViewChild does not work across component boundaries. Adding a ViewChild to my component under test (just so that I can access an ng-select during testing) seems like a bad design, especially if I have more than one ng-select in my component.
same prob bro