Skip to content

component does not re-render when async pipe is triggered #106

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
sjbuysse opened this issue Jun 10, 2020 · 3 comments
Closed

component does not re-render when async pipe is triggered #106

sjbuysse opened this issue Jun 10, 2020 · 3 comments
Labels

Comments

@sjbuysse
Copy link

sjbuysse commented Jun 10, 2020

Version info:
    "@testing-library/angular": "^9.3.1",
    "jest": "^26.0.1",
    "@angular/core": "~9.1.9",

Hi,
I made a project with nothing in it except this example component, to demonstrate the issue:

import { Component } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Component({
  selector: 'mwf-test-show',
  template: '<button (click)="toggleShow()" data-testid="toggle">toggle</button><div *ngIf="show$ | async" data-testid="getme">Here I am</div>',
})
export class TestSelectComponent {
  showSubj = new BehaviorSubject(false);
  show$ = this.showSubj.asObservable().pipe(tap(show => console.log(show)));

  toggleShow() {
    this.showSubj.next(true);
  }
}

In my test I use the waitFor function to see if the hidden div shows after toggling the Observable value to true, but it does not.
The console.log in the pipeline is triggered though. But it's as if the re-rendering does not happen.

  it('should show hidden text', async () => {
    const {component} = await setup();
    const select = component.queryByLabelText('Switch');
    const toggle = component.getByTestId('toggle');
    const hiddenText = component.queryByTestId('getme');
    expect(hiddenText).toBeNull();
    fireEvent.click(toggle);
    await waitFor(() => expect(hiddenText).not.toBeNull());
  });
@timdeschryver timdeschryver added the bug Something isn't working label Jun 10, 2020
@timdeschryver timdeschryver removed the bug Something isn't working label Jun 10, 2020
@timdeschryver
Copy link
Member

timdeschryver commented Jun 10, 2020

Hi, so this wasn't a bug after all 😅

You will have to query for the div inside the waitFor.
See the associated commit for the fix.

Fyi, it's recommended to use the findBy query to "wait" until an element becomes visible.

@sjbuysse
Copy link
Author

Thanks for the insight @timdeschryver !

@timdeschryver
Copy link
Member

🎉 This issue has been resolved in version 9.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants