Error in click handler should break a test

This issue has been created since 2022-09-21.

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

Yes

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.

See similar bugs #16821 and #46213.

Even if I patch the ErrorHandler to throw an error instead of just logging it the error will be swallowed without any reaction of TestBed and the test itself gets green.

Here the relevant parts:

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);
}
}

Please provide a link to a minimal reproduction of the bug

https://github.com/CSchulz/angular-dom-event-bug

Please provide the exception or error you saw

console.error
    ERROR Error: doStuff produced this error
        at MyComponent.doStuff (example-app-v13\src\app\exception.spec.ts:9:11)
        at MyComponent_Template_button_click_0_listener (ng:///MyComponent.js:10:22)
        at executeListenerWithErrorHandling (example-app-v13\node_modules\@angular\core\fesm2020\core.mjs:15045:16)
        at wrapListenerIn_markDirtyAndPreventDefault (example-app-v13\node_modules\@angular\core\fesm2020\core.mjs:15083:22)
        at HTMLButtonElement.<anonymous> (example-app-v13\node_modules\@angular\platform-browser\fesm2020\platform-browser.mjs:462:38)
        at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invokeTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:443:35)
        at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvokeTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:3861:43)
        at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invokeTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:442:64)
        at Object.onInvokeTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:321:104)
        at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invokeTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:442:64)
        at Object.onInvokeTask (example-app-v13\node_modules\@angular\core\fesm2020\core.mjs:25621:33)
        at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invokeTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:442:64)
        at Zone.Object.<anonymous>.Zone.runTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:214:51)
        at ZoneTask.Object.<anonymous>.ZoneTask.invokeTask [as invoke] (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:525:38)
        at invokeTask (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:1727:22)
        at globalCallback (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:1758:31)
        at HTMLButtonElement.globalZoneAwareCallback (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:1794:20)
        at HTMLButtonElement.callTheUserObjectsOperation (example-app-v13\node_modules\jsdom\lib\jsdom\living\generated\EventListener.js:26:30)
        at innerInvokeEventListeners (example-app-v13\node_modules\jsdom\lib\jsdom\living\events\EventTarget-impl.js:340:25)
        at invokeEventListeners (example-app-v13\node_modules\jsdom\lib\jsdom\living\events\EventTarget-impl.js:276:3)
        at HTMLButtonElementImpl._dispatch (example-app-v13\node_modules\jsdom\lib\jsdom\living\events\EventTarget-impl.js:223:9)
        at fireAnEvent (example-app-v13\node_modules\jsdom\lib\jsdom\living\helpers\events.js:18:36)
        at HTMLButtonElementImpl.click (example-app-v13\node_modules\jsdom\lib\jsdom\living\nodes\HTMLElement-impl.js:79:5)
        at HTMLButtonElement.click (example-app-v13\node_modules\jsdom\lib\jsdom\living\generated\HTMLElement.js:108:34)
        at example-app-v13\src\app\exception.spec.ts:19:12
        at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:409:30)
        at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:3830:43)
        at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:408:56)
        at Zone.Object.<anonymous>.Zone.run (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:169:47)
        at Object.wrappedFunc (example-app-v13\node_modules\zone.js\bundles\zone-testing-bundle.umd.js:4330:34)
        at Promise.then.completed (example-app-v13\node_modules\jest-circus\build\utils.js:333:28)
        at new Promise (<anonymous>)
        at callAsyncCircusFn (example-app-v13\node_modules\jest-circus\build\utils.js:259:10)
        at _callCircusTest (example-app-v13\node_modules\jest-circus\build\run.js:277:40)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at _runTest (example-app-v13\node_modules\jest-circus\build\run.js:209:3)
        at _runTestsForDescribeBlock (example-app-v13\node_modules\jest-circus\build\run.js:97:9)
        at _runTestsForDescribeBlock (example-app-v13\node_modules\jest-circus\build\run.js:91:9)
        at run (example-app-v13\node_modules\jest-circus\build\run.js:31:3)
        at runAndTransformResultsToJestFormat (example-app-v13\node_modules\jest-circus\build\legacy-code-todo-rewrite\jestAdapterInit.js:135:21)

      at defaultErrorLogger (node_modules/@angular/core/fesm2020/core.mjs:6509:13)
      at ErrorHandler.handleError (node_modules/@angular/core/fesm2020/core.mjs:6556:9)
      at handleError (node_modules/@angular/core/fesm2020/core.mjs:11009:34)
      at executeListenerWithErrorHandling (node_modules/@angular/core/fesm2020/core.mjs:15048:9)
      at wrapListenerIn_markDirtyAndPreventDefault (node_modules/@angular/core/fesm2020/core.mjs:15083:22)
      at HTMLButtonElement.<anonymous> (node_modules/@angular/platform-browser/fesm2020/platform-browser.mjs:462:38)
      at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invokeTask (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:443:35)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 13.3.9
Node: 16.14.2
Package Manager: yarn 1.22.19
OS: win32 x64

Angular: 13.3.11
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1303.9
@angular-devkit/build-angular   13.3.9
@angular-devkit/core            13.3.9
@angular-devkit/schematics      13.3.9
@angular/cli                    13.3.9
@schematics/angular             13.3.9
rxjs                            7.5.6
typescript                      4.5.5

Anything else?

No response

runnyren wrote this answer on 2022-09-26

Interesting

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2022-10-04
Star Count 84139
Watcher Count 3064
Fork Count 22243
Issue Count 1206

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
zotero移动到回收站的文献条目不会显示删除时间 1 2022-06-08 2022-09-22
Docs for using with AWSSDK 4 2019-09-17 2022-04-28
CVE-2021-23436 (Medium) detected in immer-9.0.5.tgz - autoclosed 1 2021-09-03 2022-09-06
CVE-2021-3807 (High) detected in ansi-regex-3.0.0.tgz 1 2021-09-21 2022-08-02
Quirky Xiaomi Mijia button device stuck in detection (Unknown remote endpoint) 5 2021-11-15 2022-07-09
(jasmin.cfg / smpp-server) Backup methods 1 2021-01-12 2022-10-02
Free users and Goldfish users cannot add more than 50 validators at once 1 2021-12-24 2022-08-02
Ignore Delimiter when field is in double quotes 1 2021-01-27 2022-09-02
Known issue: Error when trying to use VCP - Didn't find key "remote" in input 9 2021-04-20 2022-09-14
Hello, I'd like to contribute 6 2021-05-02 2022-10-04
Message stream pagination 18 2021-04-27 2022-10-04
404 link to Harmony Reporting Standard 1 2022-01-12 2022-08-31
Correlation Matrix - Strange sample disposition 7 2021-06-21 2022-09-21
TODO: add rpc gettreeinfo 0 2022-06-03 2022-09-23
How to install php-extension gd 0 2022-04-20 2022-09-14
Invalid Version Error 1 2020-05-07 2022-10-03
TypeError: c_1455079.charCodeAt is not a function" on jsfs' readFileSync 5 2021-05-03 2022-09-28
Breaking change from 2.1.3 to 2.2.1 due to new RuleType bound on Error types 9 2022-08-14 2022-09-09
TS support 1 2021-02-22 2022-01-11
webaudio wasm processor ReferenceError can't find variable Faustxxxx 3 2022-02-11 2022-09-27
deb package upgrade error 2 2021-02-12 2022-09-03
Load error if a bot has not optional `parameters` field in runtime configuration 0 2021-02-26 2022-08-02
Attributes/Filters missing in category admin 17 2021-12-30 2022-09-27
addGlPolygons not rendering polygons but the outer edge of all the shape 1 2022-01-05 2022-09-17
Clickhouse refused to start with exception message about faulty table 6 2021-09-30 2022-07-26
Feature Request: Option to close Kristall when last tab is closed 1 2021-10-27 2022-09-10
OneDrive falsely reports Ransomware while using new vault format in 1.5.0+ 15 2020-02-05 2022-07-30
Keyboard events, Custom Column Editor and navigation in datagrid 3 2022-01-17 2022-09-14
Activating a research fault localization bot on your project? 2 2021-11-10 2022-09-02
Tab.Navigator backBehavior "history" acts like backBehavior "firstRoute" 7 2022-02-22 2022-09-18
self-publishing connectors 0 2022-04-26 2022-10-02
Using `byte` with a literal range gives error, while `u8` does not 2 2022-04-22 2022-07-18
Auto Pilot Disarm 2 2021-11-04 2021-12-31
Lighthouse is not sending Client Hints 2 2021-10-26 2022-07-27
[feat_serialize] related issues compiling sire with compile sire 6 2021-07-02 2022-08-02
Failed to get entities from store: canceling statement due to conflict with recover 2 2021-02-09 2022-07-21
.NET Core StreamingHub Example, Broadcast Property Change Events 1 2021-04-20 2022-09-15
Missing sway visible attribute 1 2021-03-03 2022-09-25
Root Tree State does not update 6 2020-10-31 2022-09-25
macos's msf bug, msf auto exit program 7 2021-10-10 2022-10-01
Problem with : org.owasp.csrfguard.CsrfGuardServletContextListener ? 3 2021-07-07 2022-10-01
The "TokenPerPage" approach is not applied to AJAX requests 1 2020-05-04 2022-10-01
Logrotate while writing via logging 1 2020-05-23 2022-09-25
Modify db.cpp and FIMDB to avoid use WIN32 flag inside c++ code 1 2022-01-25 2022-08-04
Fails when included after Qt headers 2 2021-03-19 2022-09-25
The Avatar is wrongly changed when logging out 1 2021-12-08 2022-09-08
依赖的库 @react-spring/web 里有使用 Object.values,而它是 ES8(2017),所以造成低版本的手机就报错。 1 2022-06-05 2022-09-15
Functional templates errors with vue v3.1 0 2021-06-08 2022-10-02
AppVeyor failing to build v3.13-dev branch PRs 1 2021-04-16 2022-09-26
Husky doc needs update 1 2021-10-21 2022-08-08