Unit testing the virtual scroll
See original GitHub issueI want to unit test the virtual scroll please suggest the way to test this scenario I have the component.html
<virtual-scroll [items]="items" (update)="viewPortItems = $event">
<list-item *ngFor="let item of viewPortItems" [item]="item">
<div>{item.name}</div>
</list-item>
</virtual-scroll>
in my spec file i’m trying to test the debug element of virtual-scroll to check the childnodes to the length of mock data. but the child nodes doesn’t have the <div/>
element inside the <list-item/>
let ListItemElement = riskfixture.debugElement.query(By.css('list-item'));
expect(mdlListItemElement.childNodes.length).toBe(mockData.length);
when i log the ListItemElement i see below
<virtual-scroll _ngcontent-c3="">
<list-item _ngcontent-c3="">
<!--bindings={}-->
</list-item>
<router-outlet _ngcontent-c3=""></router-outlet>
</virtual-scroll>
Please help how can i achieve the unittesting
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:13
Top Results From Across the Web
Angular Material virtual scroll not rendering items in unit tests
Changing the unit test (see in the question) to following resolved it: it('should render at least 4 items', fakeAsync(() => { // <---...
Read more >Testing a Virtual List component with Cypress and Storybook
The VirtualList component leverages an inertial scroll and, since the story adds thousands of items to be rendered to fully show the VirtualList ......
Read more >Using Virtual Scroll for huge lists | Angular Cookbook
In this recipe, we'll render a list of 10,000 users and will use the Virtual Scroll functionality from the Angular CDK to improve...
Read more >Testing a Virtual List component with Cypress and Storybook
for Cypress, there is the cypress-react-unit-test library that allows you to ... The VirtualList component leverages an inertial scroll and, ...
Read more >Getting to Know the Angular CDK Virtual Scroll Feature
The problem with that is that so many elements in the DOM can cause slow initial rendering, laggy scrolling, and dirty checking on...
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
For me the solution was to manually emit the update event in the test:
If this helps anyone, I ended up just creating a fake component.
Do not import the VirtualScrollerModule into the test, instead, just define a component like this:
And add it as a declaration on