|
4 | 4 | from idom.testing import ServerMountPoint |
5 | 5 |
|
6 | 6 |
|
7 | | -HERE = Path(__file__).parent |
| 7 | +JS_DIR = Path(__file__).parent / "js" |
8 | 8 |
|
9 | 9 |
|
10 | 10 | def test_automatic_reconnect(create_driver): |
@@ -43,3 +43,35 @@ def NewComponent(): |
43 | 43 | # check that we can resume normal operation |
44 | 44 | set_state.current(1) |
45 | 45 | driver.find_element_by_id("new-component-1") |
| 46 | + |
| 47 | + |
| 48 | +def test_that_js_module_unmount_is_called(driver, driver_wait, display): |
| 49 | + module = idom.Module( |
| 50 | + "set-flag-when-unmount-is-called", |
| 51 | + source_file=JS_DIR / "set-flag-when-unmount-is-called.js", |
| 52 | + ) |
| 53 | + |
| 54 | + set_current_component = idom.Ref(None) |
| 55 | + |
| 56 | + @idom.component |
| 57 | + def ShowCurrentComponent(): |
| 58 | + current_component, set_current_component.current = idom.hooks.use_state( |
| 59 | + lambda: module.SomeComponent( |
| 60 | + {"id": "some-component", "text": "initial component"} |
| 61 | + ) |
| 62 | + ) |
| 63 | + return current_component |
| 64 | + |
| 65 | + display(ShowCurrentComponent) |
| 66 | + |
| 67 | + driver.find_element_by_id("some-component") |
| 68 | + |
| 69 | + set_current_component.current( |
| 70 | + idom.html.h1({"id": "some-other-component"}, "some other component") |
| 71 | + ) |
| 72 | + |
| 73 | + # the new component has been displayed |
| 74 | + driver.find_element_by_id("some-other-component") |
| 75 | + |
| 76 | + # the unmount callback for the old component was called |
| 77 | + driver.find_element_by_id("unmount-flag") |
0 commit comments