mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-23 12:12:59 -05:00
Introduce/improve check_js_errors and improve test_no_implicit_target (#874)
Until now, we didn't have a nice way to check that we expect a specific JS error in the web page. This PR improves check_js_errors() so that now you can pass a list of error messages that you expect. It is tricky because we need to handle (and test!) all various combinations of cases: - errors expected and found / expected but not found - unexpected errors found / not found Moreover, JS exceptions now are logged in the special category console.js_error, which means that the printed text is also available using e.g. self.console.js_error.text or self.console.all.text. However, this should never be required and it's preferred to use self.check_js_errors to check for exceptions. This fixes #795 . Finally, use the new logic to improve test_no_implicit_target.
This commit is contained in:
@@ -95,17 +95,9 @@ class TestOutput(PyScriptTest):
|
||||
self.page.locator("text=Click me").click()
|
||||
text = self.page.text_content("body")
|
||||
assert "hello" not in text
|
||||
|
||||
# currently the test infrastructure doesn't allow to easily assert that
|
||||
# js exceptions were raised this is a workaround but we need a better fix.
|
||||
# Antonio promised to write it
|
||||
assert len(self._page_errors) == 1
|
||||
console_text = self._page_errors
|
||||
assert (
|
||||
self.check_js_errors(
|
||||
"Implicit target not allowed here. Please use display(..., target=...)"
|
||||
in console_text[0].message
|
||||
)
|
||||
self._page_errors = []
|
||||
|
||||
def test_explicit_target_pyscript_tag(self):
|
||||
self.pyscript_run(
|
||||
|
||||
Reference in New Issue
Block a user