Skip to content

Commit

Permalink
test: add test case for #435
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Feb 13, 2024
1 parent 87d02f2 commit 2d0f10e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions projects/testing-library/tests/issues/issue-435.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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();
});
});

0 comments on commit 2d0f10e

Please sign in to comment.