You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So far so good. Overriding the uuid dependency works great. Now let's add a date dependency.
User model with date
structUser:Equatable{varid:UUIDvarage:Intvarcreated:Dateinit(
id:UUID?=nil,
age:Int,
created:Date?=nil){self.id = id ??{@Dependency(\.uuid)varuuidreturnuuid()}()self.age = age
self.created = created ??{@Dependency(\.date.now)varnowreturn now
}()}}
Now I get an error about the date dependency. If instead of using the TestStore's withDependencies clause we wrap it in a separate withDependencies block, the error is resolved:
This version isn't as convenient as just popping the @Shared override into the store's withDependencies block. Any reason why the date dependency breaks while the uuid dependency seems to work fine?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When overriding a
Shared
value in tests, I've found it convenient to make the declaration in thewithDependencies
clause of theTestStore
.Here's an example that works great.
User model
Feature reducer
Here's a test that overrides
@Shared(.user)
. Note thatUser.init
uses the uuid dependency.So far so good. Overriding the uuid dependency works great. Now let's add a date dependency.
User model with date
Now I get an error about the date dependency. If instead of using the
TestStore
'swithDependencies
clause we wrap it in a separatewithDependencies
block, the error is resolved:This version isn't as convenient as just popping the
@Shared
override into the store'swithDependencies
block. Any reason why the date dependency breaks while the uuid dependency seems to work fine?Beta Was this translation helpful? Give feedback.
All reactions