Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions Tests/ImmutableDataTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import Testing

// https://github.com/swiftlang/swift/issues/74882

final fileprivate class Error : Swift.Error {

final fileprivate class Error : Swift.Error, Equatable {
static func == (lhs: Error, rhs: Error) -> Bool {
lhs === rhs
}
}

final fileprivate class StateTestDouble : Sendable {
Expand Down Expand Up @@ -108,8 +110,9 @@ extension StoreTests {

extension StoreTests {
@Test func dispatchActionThrowsError() async throws {
self.reducer.returnError = Error()

let error = Error()
self.reducer.returnError = error

let store = await Store(
initialState: self.state,
reducer: self.reducer.reduce
Expand All @@ -119,15 +122,11 @@ extension StoreTests {
#expect(self.reducer.parameterAction == nil)

#expect(await store.state === self.state)
do {

await #expect(throws: error) {
try await store.dispatch(action: self.action)
#expect(false)
} catch {
let error = try #require(error as? Error)
#expect(error === self.reducer.returnError)
}

#expect(self.reducer.parameterState === self.state)
#expect(self.reducer.parameterAction === self.action)

Expand Down Expand Up @@ -158,8 +157,9 @@ extension StoreTests {

extension StoreTests {
@Test func dispatchThunkThrowsError() async throws {
self.thunk.returnError = Error()

let error = Error()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with a local constant that's known to be non-optional to make the expectation below more directly tell that we don't expect the error to be non-nil whenever the thunk's returnError is non-nil (for which the reader needs to find the conditions), but that it's always going to be a local constant set-up in this test case.

self.thunk.returnError = error

let store = await Store(
initialState: self.state,
reducer: self.reducer.reduce
Expand All @@ -169,13 +169,9 @@ extension StoreTests {
#expect(self.reducer.parameterAction == nil)

#expect(await store.state === self.state)
do {

await #expect(throws: error) {
try await store.dispatch(thunk: self.thunk.thunk)
#expect(false)
} catch {
let error = try #require(error as? Error)
#expect(error === self.thunk.returnError)
}

#expect(self.reducer.parameterState == nil)
Expand Down Expand Up @@ -220,8 +216,9 @@ extension StoreTests {

extension StoreTests {
@Test func dispatchAsyncThunkThrowsError() async throws {
self.thunk.returnError = Error()

let error = Error()
self.thunk.returnError = error

let store = await Store(
initialState: self.state,
reducer: self.reducer.reduce
Expand All @@ -231,13 +228,9 @@ extension StoreTests {
#expect(self.reducer.parameterAction == nil)

#expect(await store.state === self.state)
do {

await #expect(throws: error) {
try await store.dispatch(thunk: self.thunk.asyncThunk)
#expect(false)
} catch {
let error = try #require(error as? Error)
#expect(error === self.thunk.returnError)
}

#expect(self.reducer.parameterState == nil)
Expand Down
Loading