Why is the defaultAppStorage
dependency not always used in tests/previews?
#133
Unanswered
fruitcoder
asked this question in
Q&A
Replies: 1 comment 7 replies
-
@fruitcoder If If your application uses more than one store it should ideally control those additional stores with custom dependency keys. Take a look at how swift-sharing/Sources/Sharing/SharedKeys/AppStorageKey.swift Lines 256 to 259 in 8141fd7 You could for example introduce a |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi and thanks for the great work on this library. I'm 99% on board with the design choices you made but while adding some convenience extensions for my usage I noticed that the
defaultAppStorage
is only used as a default whenstore
isn't provided.While that makes sense (I mean it's in the name) one of the main benefits of the library (encoding key, value type, store (standard/appGroup) and default value in a single type) contradicts with isolated testing/preview scopes. In my application I use a mix of app target only and shared app group user defaults so I always specify the store. This causes the propertyWrapper to always write in the corresponding persistent user defaults.
This simple setup demonstrates my problem
Running the tests in order fails the second test when using the explicit
standard
user defaults but succeeds when not specifying a store. I wanted to know the rationale for this (I've seen tests explicitly testing this to be the expected behavior). In my code I basically have wrapper functions that ensure the behavior I have for my tests and previews:Beta Was this translation helpful? Give feedback.
All reactions