-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing rx.ComponentState
by direct initialization broken in v0.6.2+
(SetUndefinedStateVarError)
#4343
Comments
@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. |
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!
The text was updated successfully, but these errors were encountered: