def test_invalid_event_handler_args(component2, test_state):
    """Test that an invalid event handler raises an error.

    Args:
        component2: A test component.
        test_state: A test state.
    """
    # EventHandler args must match
    with pytest.raises(EventFnArgMismatchError):
        component2.create(on_blur=test_state.do_something_arg)

    # EventHandler args must have at least as many default args as the spec.
    with pytest.raises(EventFnArgMismatchError):
        component2.create(on_blur=test_state.do_something_required_optional)

    # Multiple EventHandler args: all must match
    with pytest.raises(EventFnArgMismatchError):
        component2.create(
            on_blur=[test_state.do_something_arg, test_state.do_something]
        )

    # # Event Handler types must match
    with pytest.raises(EventHandlerArgTypeMismatchError):
        component2.create(
            on_user_visited_count_changed=test_state.do_something_with_bool
        )
    with pytest.raises(EventHandlerArgTypeMismatchError):
        component2.create(on_user_list_changed=test_state.do_something_with_int)
    with pytest.raises(EventHandlerArgTypeMismatchError):
        component2.create(on_user_list_changed=test_state.do_something_with_list_int)
    with pytest.raises(EventHandlerArgTypeMismatchError):
        component2.create(
            on_user_visited_count_changed=test_state.do_something_with_bool()
        )
    with pytest.raises(EventHandlerArgTypeMismatchError):
        component2.create(on_user_list_changed=test_state.do_something_with_int())
    with pytest.raises(EventHandlerArgTypeMismatchError):
        component2.create(on_user_list_changed=test_state.do_something_with_list_int())

    component2.create(
        on_user_visited_count_changed=test_state.do_something_with_bool(False)
    )
    component2.create(on_user_list_changed=test_state.do_something_with_int(23))
    component2.create(
        on_user_list_changed=test_state.do_something_with_list_int([2321, 321])
    )

    component2.create(on_open=test_state.do_something_with_int)
    component2.create(on_open=test_state.do_something_with_bool)
    component2.create(on_user_visited_count_changed=test_state.do_something_with_int)
    component2.create(on_user_list_changed=test_state.do_something_with_list_str)

    # lambda cannot return weird values.
    with pytest.raises(ValueError):
        component2.create(on_blur=lambda: 1)
    with pytest.raises(ValueError):
        component2.create(on_blur=lambda: [1])
    with pytest.raises(ValueError):
        component2.create(
            on_blur=lambda: (test_state.do_something_arg(1), test_state.do_something)
        )

    # lambda signature must match event trigger.
    with pytest.raises(EventFnArgMismatchError):
        component2.create(on_blur=lambda _: test_state.do_something_arg(1))

    # lambda returning EventHandler must match spec
    with pytest.raises(EventFnArgMismatchError):
        component2.create(on_blur=lambda: test_state.do_something_arg)

    # Mixed EventSpec and EventHandler must match spec.
    with pytest.raises(EventFnArgMismatchError):
        component2.create(
            on_blur=lambda: [
                test_state.do_something_arg(1),
                test_state.do_something_arg,
            ]
        )
Test that an invalid event handler raises an error.

    Args:
        component2: A test component.
        test_state: A test state.
    
tests/units/components/test_component.py