Skip to content

Commit

Permalink
Add .dependency(Value.self) to preview traits
Browse files Browse the repository at this point in the history
Let's add an interface like the one that exists on test traits.
  • Loading branch information
stephencelis authored Nov 18, 2024
1 parent 3abf6f3 commit 101a640
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/Dependencies/Traits/PreviewTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
.dependencies { $0[keyPath: keyPath] = value }
}

/// A trait that overrides a preview's dependency.
///
/// - Parameter value: A dependency value to override for the test.
public static func dependency<Value: TestDependencyKey>(
_ value: Value
) -> PreviewTrait where Value == Value.Value {
.dependencies { $0[Value.self] = value }
}

/// A trait that overrides a preview's dependencies.
///
/// Useful for overriding several dependencies in a preview without incurring the nesting and
Expand Down

0 comments on commit 101a640

Please sign in to comment.