Instantly share code, notes, and snippets.

Embed
What would you like to do?
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