-
Notifications
You must be signed in to change notification settings - Fork 31
ExpectThunk proposal #19
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
04b9cff
ExpectThunk proposal
obj-p dc21ace
wowza trailing spaces
obj-p 6d06241
adding ability to pass custom assertion block
obj-p 0118c5e
refactoring ExpectThunk away from subclassing, and various tidbits
obj-p 0bf5468
using createThunkMiddleware in ExpectThunk
obj-p fc20af6
renaming ExpectThunk members
obj-p aa3e1ce
adding boundary guard and some cleanup
obj-p a674e51
code style changes
obj-p 6b86566
trailing whitespace
obj-p 0b543e4
removing type as it's inferred
obj-p 5e154b5
adding podspec
obj-p 7e638f1
adding public accessors to getsState and run
obj-p 754dbce
updating podspec
obj-p 063b055
removing podspec and adding subspec
obj-p c313633
adding preprocessor flag
obj-p 4d8c279
using isEmpty for fun
obj-p 2440ec2
adding a blurb on expect-thunk in README.md
obj-p a671f34
removing equatable from FakeAction
obj-p 0922abe
New wait/run API as well as dispatched record
obj-p 8618792
adding wait failed
obj-p 30f9a96
updating failure descriptions
obj-p ff7234f
adding blurb about ExpectThunk subspec
obj-p 5bf1d69
Adding CHANGELOG comment for ExpectThunk
obj-p f272dc9
add PR reference
DivineDominion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // | ||
| // ExpectThunk.swift | ||
| // ReSwift-Thunk-Tests | ||
| // | ||
| // Created by Jason Prasad on 2/13/19. | ||
| // Copyright © 2019 ReSwift. All rights reserved. | ||
| // | ||
|
|
||
| import XCTest | ||
| import ReSwift | ||
|
|
||
| @testable import ReSwiftThunk | ||
|
|
||
| // TODO: no longer allow subclassing | ||
| public class ExpectThunk<State: StateType> { | ||
| public typealias ActionAssertion = (Action) -> Void | ||
| private var dispatch: DispatchFunction { | ||
| return { action in | ||
| let actionAssertion = self.actionAssertions.remove(at: 0) | ||
| actionAssertion(action) | ||
| if self.actionAssertions.count == 0 { | ||
| self.expectation.fulfill() | ||
| } | ||
| } | ||
| } | ||
| private var actionAssertions = [ActionAssertion]() | ||
| private var expectedStates = [State]() | ||
| private var expectation: XCTestExpectation | ||
| private var getState: () -> State? { | ||
| return { | ||
| if self.expectedStates.count > 0 { | ||
| return self.expectedStates.removeFirst() | ||
| } else { | ||
| return nil | ||
| } | ||
| } | ||
| } | ||
| private let thunk: Thunk<State> | ||
| public init(_ thunk: Thunk<State>, description: String? = nil) { | ||
| self.thunk = thunk | ||
| expectation = XCTestExpectation(description: description ?? "\(ExpectThunk.self)") | ||
| } | ||
| } | ||
|
|
||
| extension ExpectThunk { | ||
| public func dispatches<A: Action & Equatable>(_ expected: A, file: StaticString = #file, line: UInt = #line) -> Self { | ||
obj-p marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| actionAssertions.append({ received in | ||
| XCTAssert(received as? A == expected, "dispatched action does not equal expected: \(received) \(expected)", file: file, line: line) | ||
|
||
| }) | ||
| return self | ||
| } | ||
| public func dispatches(_ matcher: @escaping ActionAssertion) -> Self { | ||
| actionAssertions.append(matcher) | ||
| return self | ||
| } | ||
| } | ||
|
|
||
| extension ExpectThunk { | ||
| func getsState(_ state: State) -> Self { | ||
| expectedStates.append(state) | ||
| return self | ||
| } | ||
| } | ||
|
|
||
| extension ExpectThunk { | ||
| func run() -> XCTestExpectation { | ||
| thunk.body(dispatch, getState) | ||
| return expectation | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.