-
Notifications
You must be signed in to change notification settings - Fork 4
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 a klyva-app #12
Comments
Ooh interesting idea. I think in a redux-based (or any app that contains the state within a react context-provider, such as jotai and recoil), the state of the "store" is restored between tests, because a new I'm thinking this would be really nice, but I'm wondering about implementation details. Approach 1: A global callback, i.e. klyva.resetAll()For us to make a Approach 2: Use jest as a platformIt's possible to use jest resetmodules or isolatemodules (https://jestjs.io/docs/en/jest-object.html#jestresetmodules) to accomplish this. How do we do this neatly? We at least need to make some official documentation that shows how to d othis. @sesam , how do you feel about these approaches? |
Just sketching here, but a really cool way of doing this would be something like this:
This actually elegantly fixes the "dream code" scenario of just providing a |
I don't think this is a bad idea, From a memory-management perspective this is optimal:
|
I'll have more confidence in my opinion once I've added tests for the components in the Klyva TodoMVC implementation, but spontaneously I'm sceptical towards a What would the gains be? Sharing atoms between tests just to call Right now in the TodoMVC implementation we simply pass atoms down from the top of the component pyramid, meaning the atoms are received as props making testing a breeze. Since splitting atoms is SO easy with Klyva, I imagine prop-drilling will feel like less of a hassle, and that you can get away without a provider mechanism even in medium-sized apps. In a large app I would likely just provide the central atom via a global system. If React I'd use context and a But it might well be that I just miss the point and the advantages of On that topic - say that |
+1, I think starting fresh with new state is conceptually much simpler than trying to reset an existing state. In React I really like context-based state management, because it's very easy to reason about for testing, and also generally easy to manually set up whatever state you need in a particular situation. I'm skeptical that prop drilling would be practical in more than a trivial app, but maybe @krawaller's right about klyva's advantages here. |
Hmm. Actually I've come around and think you're right, @uhoh-itsmaciek. I'll try rewriting the TodoMVC example with context instead to see how it feels. |
A job for WeakMap perhaps? :) I use resetAll (jest.resetAllMocks) to get back to the initial state with minimal test code. I agree it might be an edge case in many situations. I had thought that klyva-based code would avoid prop drilling / triggering a Context that in turn alerts the whole tree below. I was thinking that performance profiling a klyva app would "light up" only components subscribed to something that changed. I didn't think through how to inject / replace with fresh atoms in a tree of components, but I guess avoiding testing too deep structures at once is a good idea, then I guess reset is less needed. Probably best to leave the related PR unmerged until we find someone really needs it :) |
If we assume jest, and optionally some jest-extension, what developer experience should there be for testing an app built with klyva?
Maybe something like klyva.resetAll() to move klyva state to initial? How would this be done with a redux-based app?
The text was updated successfully, but these errors were encountered: