|
5 | 5 | import reactpy
|
6 | 6 | from reactpy import html
|
7 | 7 | from reactpy.config import REACTPY_DEBUG_MODE
|
8 |
| -from reactpy.core.hooks import LifeCycleHook, strictly_equal |
| 8 | +from reactpy.core.hooks import ( |
| 9 | + LifeCycleHook, |
| 10 | + strictly_equal, |
| 11 | + COMPONENT_DID_RENDER_EFFECT, |
| 12 | + current_hook, |
| 13 | +) |
9 | 14 | from reactpy.core.layout import Layout
|
10 | 15 | from reactpy.testing import DisplayFixture, HookCatcher, assert_reactpy_did_log, poll
|
11 | 16 | from reactpy.testing.logs import assert_reactpy_did_not_log
|
@@ -988,7 +993,7 @@ def Child2():
|
988 | 993 | await layout.render()
|
989 | 994 |
|
990 | 995 |
|
991 |
| -async def test_error_in_effect_cleanup_is_gracefully_handled(): |
| 996 | +async def test_error_in_layout_effect_cleanup_is_gracefully_handled(): |
992 | 997 | component_hook = HookCatcher()
|
993 | 998 |
|
994 | 999 | @reactpy.component
|
@@ -1227,3 +1232,28 @@ def some_component():
|
1227 | 1232 | state.current.set_value(2)
|
1228 | 1233 | await layout.render()
|
1229 | 1234 | assert state.current.value == 2
|
| 1235 | + |
| 1236 | + |
| 1237 | +async def test_error_in_component_effect_cleanup_is_gracefully_handled(): |
| 1238 | + component_hook = HookCatcher() |
| 1239 | + |
| 1240 | + @reactpy.component |
| 1241 | + @component_hook.capture |
| 1242 | + def ComponentWithEffect(): |
| 1243 | + hook = current_hook() |
| 1244 | + |
| 1245 | + def bad_effect(): |
| 1246 | + raise ValueError("The error message") |
| 1247 | + |
| 1248 | + hook.add_effect(COMPONENT_DID_RENDER_EFFECT, bad_effect) |
| 1249 | + return reactpy.html.div() |
| 1250 | + |
| 1251 | + with assert_reactpy_did_log( |
| 1252 | + match_message="Component post-render effect .*? failed", |
| 1253 | + error_type=ValueError, |
| 1254 | + match_error="The error message", |
| 1255 | + ): |
| 1256 | + async with reactpy.Layout(ComponentWithEffect()) as layout: |
| 1257 | + await layout.render() |
| 1258 | + component_hook.latest.schedule_render() |
| 1259 | + await layout.render() # no error |
0 commit comments