async def test_state_with_invalid_yield(capsys, mock_app):
    """Test that an error is thrown when a state yields an invalid value.

    Args:
        capsys: Pytest fixture for capture standard streams.
        mock_app: Mock app fixture.
    """

    class StateWithInvalidYield(BaseState):
        """A state that yields an invalid value."""

        def invalid_handler(self):
            """Invalid handler.

            Yields:
                an invalid value.
            """
            yield 1

    invalid_state = StateWithInvalidYield()
    async for update in invalid_state._process(
        rx.event.Event(token="fake_token", name="invalid_handler")
    ):
        assert not update.delta
        assert update.events == rx.event.fix_events(
            [
                rx.toast(
                    "An error occurred.",
                    level="error",
                    fallback_to_alert=True,
                    description="TypeError: Your handler test_state_with_invalid_yield.<locals>.StateWithInvalidYield.invalid_handler must only return/yield: None, Events or other EventHandlers referenced by their class (i.e. using `type(self)` or other class references). Returned events of types <class 'int'>..<br/>See logs for details.",
                    id="backend_error",
                    position="top-center",
                    style={"width": "500px"},
                )
            ],
            token="",
        )
    captured = capsys.readouterr()
    assert "must only return/yield: None, Events or other EventHandlers" in captured.out
Test that an error is thrown when a state yields an invalid value.

    Args:
        capsys: Pytest fixture for capture standard streams.
        mock_app: Mock app fixture.
    
tests/units/test_state.py