Closed
Description
Hello,
I have a component where I am using the RXJS's throwError
method to re-throw an error from a catchError
operator.
The test itself passes but the issue is that the error thrown by throwError makes the next test fail.
Here is a reproduction:
import {Component} from '@angular/core';
import {throwError} from 'rxjs';
@Component({
selector: 'app-test',
template: `<button (click)="onTest()">Test</button>`,
styles: [],
})
export class TestComponent {
onTest() {
throwError(() => new Error('myerror')).subscribe();
}
}
import {render, screen} from '@testing-library/angular';
import userEvent from '@testing-library/user-event';
import {TestComponent} from './test.component';
describe('TestComponent', () => {
it('does not fail', async () => {
await render(TestComponent);
await userEvent.click(screen.getByText('Test'));
});
it('fails because of the previous one', async () => {
await render(TestComponent);
await userEvent.click(screen.getByText('Test'));
});
});

How can i avoid the error to make the test fail ?
Thanks
Metadata
Metadata
Assignees
Labels
No labels