22
33import pytest
44import idom
5- from idom import Module , install
5+ from idom import Module
6+
7+ from tests .general_utils import patch_slots_object
68
79HERE = Path (__file__ ).parent
810
@@ -31,20 +33,6 @@ def test_installed_module(driver, display, victory):
3133 driver .find_element_by_class_name ("VictoryContainer" )
3234
3335
34- def test_install_checks_client_implementation (client_implementation ):
35- class MockClientImplementation :
36- def web_module_names (self ):
37- return set ()
38-
39- client_implementation .current = MockClientImplementation ()
40-
41- with pytest .raises (
42- RuntimeError ,
43- match = r"Successfuly installed .* but client implementation .* failed to discover .*" ,
44- ):
45- install ("jquery@3.5.0" , ignore_installed = True )
46-
47-
4836def test_reference_pre_installed_module (victory ):
4937 assert victory .url == idom .Module ("victory" ).url
5038
@@ -55,37 +43,6 @@ def test_module_from_url():
5543 assert jquery .url == url
5644
5745
58- def test_module_uses_current_client_implementation (client_implementation ):
59- class MockClientImplementation :
60- def web_module_url (self , package_name ):
61- return f"./mock/url/to/module-{ package_name } .js"
62-
63- def web_module_exports (self , package_name ):
64- return ["x" , "y" , "z" ]
65-
66- def web_module_exists (self , package_name ):
67- return package_name == "fake-name"
68-
69- def web_module_names (self ):
70- raise NotImplementedError ()
71-
72- def web_module_path (self , package_name ):
73- raise NotImplementedError ()
74-
75- def add_web_module (self , package_name , source ):
76- raise NotImplementedError ()
77-
78- client_implementation .current = MockClientImplementation ()
79-
80- fake = Module ("fake-name" )
81- assert fake .url == "./mock/url/to/module-fake-name.js"
82- assert list (fake .exports ) == ["x" , "y" , "z" ]
83- assert fake .fallback is None
84-
85- with pytest .raises (ValueError , match = "does not export 'DoesNotExist'" ):
86- fake .declare ("DoesNotExist" )
87-
88-
8946def test_module_from_source (driver , driver_wait , display ):
9047 test_module = Module ("test-module" , source_file = HERE / "test_js_module.js" )
9148
@@ -106,3 +63,9 @@ def ShowButton():
10663 client_button = driver .find_element_by_id ("test-button" )
10764 client_button .click ()
10865 driver_wait .until (lambda dvr : response_data .current == 10 )
66+
67+
68+ def test_module_checks_export_names (victory ):
69+ with patch_slots_object (victory , "_export_names" , []):
70+ with pytest .raises (ValueError , match = "does not export" ):
71+ victory .decalare ("VictoryBar" )
0 commit comments