fix exception thrown but not shown in DOM in event handler (#1131)

* fix exception not thrown in event handler

* fix implicit display test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Madhur Tandon
2023-01-25 20:08:05 +05:30
committed by GitHub
parent 4124bb5edc
commit 697ac9de9a
4 changed files with 43 additions and 8 deletions

View File

@@ -43,6 +43,30 @@ class TestBasic(PyScriptTest):
assert tb_lines[0] == "Traceback (most recent call last):"
assert tb_lines[-1] == "Exception: this is an error"
def test_python_exception_in_event_handler(self):
self.pyscript_run(
"""
<button py-click="onclick()">Click me</button>
<py-script>
def onclick():
raise Exception("this is an error inside handler")
</py-script>
"""
)
self.page.locator("button").click()
## error in console
tb_lines = self.console.error.lines[-1].splitlines()
assert tb_lines[0] == "[pyexec] Python exception:"
assert tb_lines[1] == "Traceback (most recent call last):"
assert tb_lines[-1] == "Exception: this is an error inside handler"
## error in DOM
tb_lines = self.page.locator(".py-error").inner_text().splitlines()
assert tb_lines[0] == "Traceback (most recent call last):"
assert tb_lines[-1] == "Exception: this is an error inside handler"
def test_execution_in_order(self):
"""
Check that they py-script tags are executed in the same order they are