question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Open dropdown and Select one of value from dropdown in Angular unit test

See original GitHub issue

Describe 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

image

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):

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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
aserrariccommented, Jun 19, 2019

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

0reactions
Arcanorumcommented, Dec 9, 2020

same prob bro

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Test Select Dropdown - ConcretePage.com
This page will walk through Angular unit test select dropdown example. ... We will test the changing of selected value from dropdown.
Read more >
How to perform unit test on dropdown when click event happens
Now, for Unit test: it('should update the customer number on selecting a value from drop down', () => { component.customers = [{ ownerid:...
Read more >
How do I get the value of the selected dropdown menu item ...
Learn how to determine which dropdown menu the user selected in your Angular template, and get its value.
Read more >
How to Handle Dropdown in Cypress | BrowserStack
Cypress has the chaining command select() using which can easily select the drop-down values.
Read more >
Usage of Selenium Select Class for Handling Dropdown ...
In the above java command, we select the third value in the drop down using the selectByIndex() method and parameterizing it with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found