diff --git a/tests/units/components/test_component.py b/tests/units/components/test_component.py index 89f4bd4171..1e4755f058 100644 --- a/tests/units/components/test_component.py +++ b/tests/units/components/test_component.py @@ -908,26 +908,12 @@ def test_invalid_event_handler_args(component2, test_state): # EventHandler args must match with pytest.raises(EventFnArgMismatch): component2.create(on_click=test_state.do_something_arg) - # Does not raise because event handlers are allowed to have less args than the spec. - # with pytest.raises(EventFnArgMismatch): - # component2.create(on_open=test_state.do_something) - # with pytest.raises(EventFnArgMismatch): - # component2.create(on_prop_event=test_state.do_something) # Multiple EventHandler args: all must match with pytest.raises(EventFnArgMismatch): component2.create( on_click=[test_state.do_something_arg, test_state.do_something] ) - # Same as above - # with pytest.raises(EventFnArgMismatch): - # component2.create( - # on_open=[test_state.do_something_arg, test_state.do_something] - # ) - # with pytest.raises(EventFnArgMismatch): - # component2.create( - # on_prop_event=[test_state.do_something_arg, test_state.do_something] - # ) # Enable when 0.7.0 happens # # Event Handler types must match @@ -958,18 +944,10 @@ def test_invalid_event_handler_args(component2, test_state): # lambda signature must match event trigger. with pytest.raises(EventFnArgMismatch): component2.create(on_click=lambda _: test_state.do_something_arg(1)) - # with pytest.raises(EventFnArgMismatch): - # component2.create(on_open=lambda: test_state.do_something) - # with pytest.raises(EventFnArgMismatch): - # component2.create(on_prop_event=lambda: test_state.do_something) # lambda returning EventHandler must match spec with pytest.raises(EventFnArgMismatch): component2.create(on_click=lambda: test_state.do_something_arg) - # with pytest.raises(EventFnArgMismatch): - # component2.create(on_open=lambda _: test_state.do_something) - # with pytest.raises(EventFnArgMismatch): - # component2.create(on_prop_event=lambda _: test_state.do_something) # Mixed EventSpec and EventHandler must match spec. with pytest.raises(EventFnArgMismatch): @@ -979,17 +957,6 @@ def test_invalid_event_handler_args(component2, test_state): test_state.do_something_arg, ] ) - # with pytest.raises(EventFnArgMismatch): - # component2.create( - # on_open=lambda _: [test_state.do_something_arg(1), test_state.do_something] - # ) - # with pytest.raises(EventFnArgMismatch): - # component2.create( - # on_prop_event=lambda _: [ - # test_state.do_something_arg(1), - # test_state.do_something, - # ] - # ) def test_valid_event_handler_args(component2, test_state): @@ -1003,6 +970,10 @@ def test_valid_event_handler_args(component2, test_state): component2.create(on_click=test_state.do_something) component2.create(on_click=test_state.do_something_arg(1)) + # Does not raise because event handlers are allowed to have less args than the spec. + component2.create(on_open=test_state.do_something) + component2.create(on_prop_event=test_state.do_something) + # Controlled event handlers should take args. component2.create(on_open=test_state.do_something_arg) component2.create(on_prop_event=test_state.do_something_arg) @@ -1011,10 +982,20 @@ def test_valid_event_handler_args(component2, test_state): component2.create(on_open=test_state.do_something()) component2.create(on_prop_event=test_state.do_something()) + # Multiple EventHandler args: all must match + component2.create(on_open=[test_state.do_something_arg, test_state.do_something]) + component2.create( + on_prop_event=[test_state.do_something_arg, test_state.do_something] + ) + # lambda returning EventHandler is okay if the spec matches. component2.create(on_click=lambda: test_state.do_something) component2.create(on_open=lambda _: test_state.do_something_arg) component2.create(on_prop_event=lambda _: test_state.do_something_arg) + component2.create(on_open=lambda: test_state.do_something) + component2.create(on_prop_event=lambda: test_state.do_something) + component2.create(on_open=lambda _: test_state.do_something) + component2.create(on_prop_event=lambda _: test_state.do_something) # lambda can always return an EventSpec. component2.create(on_click=lambda: test_state.do_something_arg(1)) @@ -1047,6 +1028,15 @@ def test_valid_event_handler_args(component2, test_state): component2.create( on_prop_event=lambda _: [test_state.do_something_arg, test_state.do_something()] ) + component2.create( + on_open=lambda _: [test_state.do_something_arg(1), test_state.do_something] + ) + component2.create( + on_prop_event=lambda _: [ + test_state.do_something_arg(1), + test_state.do_something, + ] + ) def test_get_hooks_nested(component1, component2, component3):