Closed TimChild closed 1 week ago
@TimChild i suggest adjusting the test to smth like this:
from typing import override
import reflex as rx
class DummyComponent(rx.ComponentState):
some_var: int = 0
def do_something(self):
self.some_var += 1
@override
@classmethod
def get_component(cls):
return rx.box()
def test_direct_component_init():
state_cls = DummyComponent.create().State
assert state_cls is not None
state_inst = state_cls()
assert isinstance(state_inst, DummyComponent)
assert state_inst.some_var == 0
state_inst.do_something()
assert state_inst.some_var == 1
@reflex-dev maybe we should raise an exception if someone tries to directly instantiate a ComponentState?
@benedikt-bartscher , oh yes, that make sense now that I see it, thanks!
It would definitely be nice to get a helpful error message there, or for it to be possible to directly instantiate if in a testing environment, but your solution does make sense.
@TimChild I implemented better error messages in #4347
Describe the bug Before v0.6.2, it was possible to directly initialize
ComponentState
for testing purposes (same as directly initializingState
instances), but sincev0.6.2
I get an error:I've not been able to really narrow down where the issue comes from, but below is a very minimal example that demonstrates the issue.
To Reproduce Steps to reproduce the behavior:
Running pytest on this with
reflex==0.6.1
passes... Withreflex==0.6.2
(or higher) it fails.Expected behavior Should be able to directly initialize ComponentState instances for testing purposes.
Specifics (please complete the following information):
Is there a different recommended way to test basic behaviour of ComponetState subclasses? (and is this still the right approach to take with
rx.State
subclasses if not forrx.ComponentState
subclasses?).Thanks!