Skip to content
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

Inject error when using async pipe #435

Closed
Thyregod opened this issue Feb 13, 2024 · 2 comments
Closed

Inject error when using async pipe #435

Thyregod opened this issue Feb 13, 2024 · 2 comments

Comments

@Thyregod
Copy link

Description:
I face a NG0203: inject error when I use async pipe inside template when testing.

Error:
image

How to reproduce:

  1. Add the code as described below
  2. Run tests
  3. See error in terminal
// demo.component.spec.ts

import { screen, render } from '@testing-library/angular';
import { CommonModule } from '@angular/common';
import { BehaviorSubject } from 'rxjs';
import { Component, Inject, Injectable } from '@angular/core';

// Service
@Injectable()
export class DemoService {
  buttonTitle = new BehaviorSubject<string>('Click me');
}

// Component
@Component({
  selector: 'demo',
  standalone: true,
  imports: [CommonModule],
  providers: [DemoService],
  template: `
    <button>
      <!-- 👇 I only get the Inject error when I use the async pipe here -->
      {{ demoService.buttonTitle | async }}
    </button>
  `,
})
export class DemoComponent {
  constructor(@Inject(DemoService) public demoService: DemoService) {}
}

// Test
describe(DemoComponent.name, () => {
  it('should render button', async () => {
    await render(DemoComponent);

    const button = screen.getByRole('button', {
      name: /Click me/,
    });

    expect(button).toBeVisible();
  });
});

Question:
Do you have any idea why this occurs and if it has to do with angular-testing-library?

timdeschryver added a commit that referenced this issue Feb 13, 2024
@timdeschryver
Copy link
Member

Hi, I'm not able to reproduce this.
What version of Angular / Testing Library are you using?

For reference, this works #436

timdeschryver added a commit that referenced this issue Feb 13, 2024
@Thyregod
Copy link
Author

Hi Tim
Thanks for your fast respone.

Apparently it had to do with a customisation we had in our testing setup.
Sorry for the inconvenience.

timdeschryver added a commit that referenced this issue Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants