Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #Preview and @Test traits for overriding dependencies #274

Merged
merged 20 commits into from
Sep 12, 2024

Conversation

stephencelis
Copy link
Member

@stephencelis stephencelis commented Sep 11, 2024

This PR introduces new traits for overriding dependencies.

In previews:

#Preview(
  .dependencies {
    $0.apiClient = .failsOnSignUp
    $0.date.now = Date(timeIntervalSince1970: 1234567890)
    $0.continuousClock = .immediate
  }
) {
  // The 'apiClient', 'date' and 'continuousClock' dependencies
  // are all overridden in this preview.
  SignUpView(
    model: SignUpModel()
  )
}

In tests:

import DependenciesTestSupport

@Test(
  .dependency(\.apiClient, .failsOnSignUp),
  .dependency(\.date.now, Date(timeIntervalSince1970: 1234567890)),
  .dependency(\.continuousClock, .immediate)  
)
func feature() {
  let model = SignUpModel()
  // The 'apiClient', 'date' and 'continuousClock' dependencies
  // are all overridden in this scope.
}

README.md Outdated Show resolved Hide resolved
@stephencelis stephencelis merged commit 5361983 into main Sep 12, 2024
5 checks passed
@stephencelis stephencelis deleted the preview-test-trait branch September 12, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants