Skip to content

JS TypeError triggered by PyButton.connectedCallback #673

@antocuni

Description

@antocuni

This is a bug which was discovered while developing #663 .
If you try to execute TestPyButton.test_on_click:

class TestPyButton(PyScriptTest):
@pytest.mark.xfail
def test_on_click(self):
"""
currently this test fails for a bad reason which is unrelated to
py-button. During the page loading, the following JS exception occur,
in base.ts:BaseEvalElement.evaluate
[JS exception ] TypeError: Cannot use 'in' operator to search for 'runPythonAsync' in undefined
at http://127.0.0.1:8080/build/pyscript.js:305:38
at Object.subscribe (http://127.0.0.1:8080/build/pyscript.js:46:13)
at PyButton.runAfterRuntimeInitialized (http://127.0.0.1:8080/build/pyscript.js:304:27)
at PyButton.connectedCallback (http://127.0.0.1:8080/build/pyscript.js:26856:18)
at http://127.0.0.1:8080/build/pyscript.js:27075:20
at http://127.0.0.1:8080/build/pyscript.js:27093:3
""" # noqa: E501
self.pyscript_run(
"""
<py-button label="my button">
import js
def on_click(evt):
js.console.info('clicked!')
</py-button>
"""
)
assert self.console.info.lines == []
self.page.locator("text=my button").click()
self.page.locator("text=my button").click()
assert self.console.info.lines == ["clicked!", "clicked!"]

You notice that it raises the following JS exception:

base.ts:191 Uncaught TypeError: Cannot use 'in' operator to search for 'runPythonAsync' in undefined
    at base.ts:191:33
    at Object.subscribe (index.mjs:50:9)
    at PyButton.runAfterRuntimeInitialized (base.ts:190:23)
    at PyButton.connectedCallback (pybutton.ts:68:14)
    at main.ts:20:34
    at main.ts:38:25

I didn't investigate further, but it seems something which should be fixed.

Assuming that #663 will be merged soon, once this issue is fixed we also need to remove the @pytest.mark.xfail decorator from the test.

EDIT: #663 was merged, and #676 found another test which fails because of this:

@pytest.mark.xfail(reason="JsError, issue #673")
def test_todo_pylist(self):
# XXX improve this test
self.goto("examples/todo-pylist.html")
self.wait_for_pyscript()
assert self.page.title() == "Todo App"
wait_for_render(self.page, "*", "<input.*?id=['\"]new-task-content['\"].*?>")

In order to properly fix this issue, a PR should:

  • add a new test minimal test (e.g. in test_01_basic.py) which showcases the problem
  • fix the bug :)
  • remove the @pytest.mark.xfail from the two tests mentioned above and ensure that they pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang: typescriptRelated to the Typescript languagetype: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions