Does mst support computed functions ? #1997
-
I would like to be able to mock a computed getter on a 'view store' but since the objects are immutable, I cant mock properties. Is there a way to make them non immutable for tests or to change my property accessor into a computed function instead. This is what it currently looks like:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @ansachs - sorry it took so long for a response. I'm not sure if this is precisely what you're looking for, but in a lot of the tests I write for work where we need MST to return certain values, I use either applySnapshot or applyPatch to directly manipulate the store. It feels a little "wrong" to be reaching in and manipulating the store sometimes in the middle of a test, but if you were planning on mocking properties anyway, I think this approach is analogous (and in many ways, a little more robust, since it will trigger patch/snapshot listeners and such). Is that useful? Did you figure this out in a different way to meet your needs? Would love to hear what worked or not for you. |
Beta Was this translation helpful? Give feedback.
Hey @ansachs - sorry it took so long for a response.
I'm not sure if this is precisely what you're looking for, but in a lot of the tests I write for work where we need MST to return certain values, I use either applySnapshot or applyPatch to directly manipulate the store.
It feels a little "wrong" to be reaching in and manipulating the store sometimes in the middle of a test, but if you were planning on mocking properties anyway, I think this approach is analogous (and in many ways, a little more robust, since it will trigger patch/snapshot listeners and such).
Is that useful? Did you figure this out in a different way to meet your needs? Would love to hear what worked or not for you.