-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix race condition where the error box didn't always display (#788)
- Loading branch information
1 parent
5e02e37
commit 5b4407a
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import asyncio | ||
import time | ||
from typing import Generator | ||
|
||
import mesop as me | ||
|
||
|
||
@me.page(path="/event_handler_error") | ||
def page(): | ||
me.text("Hello, world!") | ||
me.button(label="Regular event handler", on_click=on_click) | ||
me.button(label="Generator event handler", on_click=on_click_generator) | ||
me.button(label="Yield from event handler", on_click=on_click_yield_from) | ||
me.button( | ||
label="Async generator event handler", on_click=on_click_async_generator | ||
) | ||
|
||
|
||
def on_click(e: me.ClickEvent): | ||
raise Exception("Error in on_click.") | ||
|
||
|
||
def on_click_generator(e: me.ClickEvent): | ||
yield | ||
raise Exception("Error in on_click_generator.") | ||
|
||
|
||
def on_click_yield_from(e: me.ClickEvent) -> Generator[None, None, None]: | ||
yield from a_generator() | ||
|
||
|
||
def a_generator(): | ||
yield | ||
time.sleep(0.2) | ||
raise Exception("Error in a_generator.") | ||
|
||
|
||
async def on_click_async_generator(e: me.ClickEvent): | ||
await asyncio.sleep(0.2) | ||
yield | ||
raise Exception("Error in on_click_async_generator.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {test, expect} from '@playwright/test'; | ||
|
||
test('event handler error message is shown', async ({page}) => { | ||
await page.goto('/event_handler_error'); | ||
|
||
// Regular event handler | ||
await page.getByRole('button', {name: 'Regular event handler'}).click(); | ||
await expect( | ||
page.getByText('Error in on_click.', {exact: true}), | ||
).toBeVisible(); | ||
await page.locator('button').filter({hasText: 'close'}).click(); | ||
|
||
// Generator event handler | ||
await page | ||
.getByRole('button', {name: 'Generator event handler', exact: true}) | ||
.click(); | ||
await expect( | ||
page.getByText('Error in on_click_generator.', {exact: true}), | ||
).toBeVisible(); | ||
await page.locator('button').filter({hasText: 'close'}).click(); | ||
|
||
// Yield from event handler | ||
await page.getByRole('button', {name: 'Yield from event handler'}).click(); | ||
await expect( | ||
page.getByText('Error in a_generator.', {exact: true}), | ||
).toBeVisible(); | ||
await page.locator('button').filter({hasText: 'close'}).click(); | ||
|
||
// Async generator event handler | ||
await page | ||
.getByRole('button', {name: 'Async generator event handler'}) | ||
.click(); | ||
await expect( | ||
page.getByText('Error in on_click_async_generator.', {exact: true}), | ||
).toBeVisible(); | ||
await page.locator('button').filter({hasText: 'close'}).click(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters