Visitar URL original
TestBed: provide an option to treat a test as failed when an error is thrown in a listener · Issue #46213 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20220712012127/https://github.com/angular/angular/issues/46213
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

TestBed: provide an option to treat a test as failed when an error is thrown in a listener #46213

Open
AndrewKushnir opened this issue Jun 1, 2022 · 2 comments
Labels
Milestone

Comments

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Jun 1, 2022 •

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Currently, when a listener produces an error during the test execution, it doesn't affect the outcome of the test: the error is reported to the ErrorHandler and it logs it into the console. Here is a relevant part of code:

function executeListenerWithErrorHandling(
lView: LView, context: {}|null, listenerFn: (e?: any) => any, e: any): boolean {
try {
profiler(ProfilerEvent.OutputStart, context, listenerFn);
// Only explicitly returning false from a listener should preventDefault
return listenerFn(e) !== false;
} catch (error) {
handleError(lView, error);
return false;
} finally {
profiler(ProfilerEvent.OutputEnd, context, listenerFn);
}
}

Here is an example TesBed test:

import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';

@Component({
  template: `<button (click)="doStuff()">Click</button>`
})
class MyComponent {
  doStuff() {
    throw new Error('doStuff produced this error');
  }
}

describe('MyComponent', () => {
  it('should create the app', () => {
    TestBed.configureTestingModule({declarations: [MyComponent]});
    const fixture = TestBed.createComponent(MyComponent);

    const button = fixture.nativeElement.querySelector('button')!;
    button.click();
    fixture.detectChanges();

    // any valid assertion
    expect(1).toEqual(1);
  });
});

Changing this behavior would be breaking, so we can consider adding a TestBed flag to force the test to fail in this case (and generally in any case when an error is reported to the ErrorHandler).

@AndrewKushnir AndrewKushnir added feature comp: core hotlist: google labels Jun 1, 2022
@ngbot ngbot bot added this to the Backlog milestone Jun 1, 2022
@ngbot ngbot bot added this to the Backlog milestone Jun 1, 2022
@ngbot ngbot bot added this to the Backlog milestone Jun 1, 2022
@ngbot ngbot bot added this to the Backlog milestone Jun 1, 2022
@angular-robot
Copy link

@angular-robot angular-robot bot commented Jun 2, 2022

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

@angular-robot
Copy link

@angular-robot angular-robot bot commented Jul 11, 2022

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

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