Skip to content

Commit e2b0609

Browse files
authored
Add .dependency(Value.self) to preview traits (#313)
Let's add an interface like the one that exists on test traits.
1 parent 3abf6f3 commit e2b0609

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/Dependencies/Traits/PreviewTrait.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
.dependencies { $0[keyPath: keyPath] = value }
2727
}
2828

29+
/// A trait that overrides a preview's dependency.
30+
///
31+
/// - Parameter value: A dependency value to override for the test.
32+
public static func dependency<Value: TestDependencyKey>(
33+
_ value: Value
34+
) -> PreviewTrait where Value == Value.Value {
35+
.dependencies { $0[Value.self] = value }
36+
}
37+
2938
/// A trait that overrides a preview's dependencies.
3039
///
3140
/// Useful for overriding several dependencies in a preview without incurring the nesting and

0 commit comments

Comments
 (0)