Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
adding ability to pass custom assertion block
  • Loading branch information
obj-p committed Feb 14, 2019
commit 6d062416716d0ee59e220c6e5a31fc58a86a649d
12 changes: 8 additions & 4 deletions ReSwift-ThunkTests/ExpectThunk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import ReSwift

@testable import ReSwiftThunk

class ExpectThunk<State: StateType>: XCTestExpectation {
private typealias ActionMatcher = (Action) -> Void
public class ExpectThunk<State: StateType>: XCTestExpectation {
public typealias ActionMatcher = (Action) -> Void
private var dispatch: DispatchFunction {
return { action in
let matcher = self.expectedActions.remove(at: 0)
Expand All @@ -34,7 +34,7 @@ class ExpectThunk<State: StateType>: XCTestExpectation {
}
}
private let thunk: Thunk<State>
init(_ thunk: Thunk<State>, description: String? = nil) {
public init(_ thunk: Thunk<State>, description: String? = nil) {
self.thunk = thunk
super.init(description: description ?? "\(ExpectThunk.self)")
}
Expand All @@ -45,12 +45,16 @@ class ExpectThunk<State: StateType>: XCTestExpectation {
}

extension ExpectThunk {
func dispatches<A: Action & Equatable>(_ expected: A, file: StaticString = #file, line: UInt = #line) -> Self {
public func dispatches<A: Action & Equatable>(_ expected: A, file: StaticString = #file, line: UInt = #line) -> Self {
expectedActions.append({ received in
XCTAssert(received as? A == expected, "dispatched action does not equal expected: \(received) \(expected)", file: file, line: line)

Choose a reason for hiding this comment

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

Line Length Violation: Line should be 120 characters or less: currently 143 characters (line_length)

})
return self
}
public func dispatches(_ matcher: @escaping ActionMatcher) -> Self {
expectedActions.append(matcher)
return self
}
}

extension ExpectThunk {
Expand Down
10 changes: 8 additions & 2 deletions ReSwift-ThunkTests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ class Tests: XCTestCase {
let expect = ExpectThunk<FakeState>(thunk)
.dispatches(FakeAction())
.getsState(FakeState())
.dispatches(FakeAction())
.dispatches {
XCTAssert($0 as? FakeAction == FakeAction())
}
.dispatches(AnotherFakeAction())
.getsState(FakeState())
.run()
/* NOTE: this will fail as it asserts order!
let expect = ExpectThunk<FakeState>(thunk)
.dispatches(FakeAction())
.getsState(FakeState())
.dispatches(AnotherFakeAction())
.dispatches(FakeAction())
.dispatches {
XCTAssert($0 as? FakeAction == FakeAction())
}
.getsState(FakeState())
.run()
*/
wait(for: [expect], timeout: 1.0)
Expand Down