Skip to content

Instantly share code, notes, and snippets.

@fabiothiroki
Created February 12, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiothiroki/34be895783f0d969411c6b4548eb13a1 to your computer and use it in GitHub Desktop.
Save fabiothiroki/34be895783f0d969411c6b4548eb13a1 to your computer and use it in GitHub Desktop.
Reducer tests
class AppReducerSpec: XCTestCase {
func testShouldReturnInitialState() {
let newState = reducer.reduce(action: FetchPlacesAction(), state: nil)
XCTAssertEqual(newState, FetchedPlacesState(places: .loading))
}
func testShouldChangeStateAfterSuccessfulRequest() {
let places = LocationPlaces()
let action = SetPlacesAction.init(places: places)
let newState = reducer.reduce(action: action, state: nil)
XCTAssertEqual(newState, FetchedPlacesState(places: Result.finished(places)))
}
func testShouldChangeStateAfterErrorRequest() {
let mockError = NSError(domain: "Mock error", code: 42, userInfo: nil )
let action = SetErrorAction(error: mockError)
let newState = reducer.reduce(action: action, state: nil)
XCTAssertEqual(newState, FetchedPlacesState(places: Result.failed))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment