Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Nov 4, 2024
1 parent dc866b3 commit baa0099
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions Tests/DependenciesTests/DependencyValuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,16 @@ final class DependencyValuesTests: XCTestCase {
}

#if !os(Linux) && !os(WASI) && !os(Windows)
func testPrepareDependencies_alreadyPrepared() {
func testPrepareDependencies_MultiplePreparesWithNoAccessBetween() {
prepareDependencies {
$0.date = DateGenerator { Date(timeIntervalSinceReferenceDate: 0) }
}
XCTExpectFailure {
XCTExpectFailure(
"""
Currently this fails, but in the future we may allow a dependency to be changed in
multiple 'prepareDependencies' as long as the dependency has not yet been accessed.
"""
) {
$0.compactDescription == """
failed - @Dependency(\\.date) has already been accessed or prepared.
Expand All @@ -737,6 +742,36 @@ final class DependencyValuesTests: XCTestCase {
}
#endif

#if !os(Linux) && !os(WASI) && !os(Windows)
func testPrepareDependencies_MultiplePreparesWithAccessBetween() {
prepareDependencies {
$0.date = DateGenerator { Date(timeIntervalSinceReferenceDate: 0) }
}
XCTExpectFailure {
$0.compactDescription == """
failed - @Dependency(\\.date) has already been accessed or prepared.
Key:
DependencyValues.DateGeneratorKey
Value:
DateGenerator
A global dependency can only be prepared a single time and cannot be accessed \
beforehand. Prepare dependencies as early as possible in the lifecycle of your \
application.
To temporarily override a dependency in your application, use 'withDependencies' to do \
so in a well-defined scope.
"""
}
@Dependency(\.date) var date
_ = date
prepareDependencies {
$0.date = DateGenerator { Date(timeIntervalSince1970: 0) }
}
}
#endif

func testPrepareDependencies_setDependencyMultipleTimesInSamePrepare() {
prepareDependencies {
$0.date = DateGenerator { Date(timeIntervalSinceReferenceDate: 42) }
Expand Down Expand Up @@ -771,7 +806,8 @@ final class DependencyValuesTests: XCTestCase {
func testPrepareDependencies_PrepareContext() {
prepareDependencies { $0.context = .live }

XCTTODO("""
XCTTODO(
"""
Currently 'context' cannot be overridden with 'prepareDependencies'.
""")
@Dependency(\.date) var date
Expand Down

0 comments on commit baa0099

Please sign in to comment.