Skip to content

remove extra element added by test fixture #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/idom/testing/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
from types import TracebackType
from typing import Any

from playwright.async_api import Browser, BrowserContext, Page, async_playwright
from playwright.async_api import (
Browser,
BrowserContext,
ElementHandle,
Page,
async_playwright,
)

from idom import html
from idom.config import IDOM_TESTING_DEFAULT_TIMEOUT
Expand All @@ -30,22 +36,24 @@ def __init__(
self.page = driver
else:
self._browser = driver
self._next_view_id = 0

async def show(
self,
component: RootComponentConstructor,
) -> None:
self._next_view_id += 1
view_id = f"display-{self._next_view_id}"
self.backend.mount(lambda: html.div({"id": view_id}, component()))

self.backend.mount(component)
await self.goto("/")
await self.page.wait_for_selector(f"#{view_id}", state="attached")
await self.root_element() # check that root element is attached

async def goto(self, path: str, query: Any | None = None) -> None:
await self.page.goto(self.backend.url(path, query))

async def root_element(self) -> ElementHandle:
element = await self.page.wait_for_selector(f"#app", state="attached")
if element is None:
raise RuntimeError("Root element not attached") # pragma: no cover
return element

async def __aenter__(self) -> DisplayFixture:
es = self._exit_stack = AsyncExitStack()

Expand Down