/
TypeHelperTests.swift
67 lines (52 loc) · 1.61 KB
/
TypeHelperTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// TypeHelperTests.swift
// ReSwift
//
// Created by Benjamin Encz on 12/20/15.
// Copyright © 2015 ReSwift Community. All rights reserved.
//
import XCTest
/**
@testable import for testing of `withSpecificTypes`
*/
@testable import ReSwift
struct AppState1 {}
struct AppState2 {}
class TypeHelperTests: XCTestCase {
/**
it calls methods if the source type can be casted into the function signature type
*/
func testSourceTypeCasting() {
var called = false
let reducerFunction: (Action, AppState1?) -> AppState1 = { action, state in
called = true
return state ?? AppState1()
}
withSpecificTypes(NoOpAction(), state: AppState1(), function: reducerFunction)
XCTAssertTrue(called)
}
/**
it calls the method if the source type is nil
*/
func testCallsIfSourceTypeIsNil() {
var called = false
let reducerFunction: (Action, AppState1?) -> AppState1 = { action, state in
called = true
return state ?? AppState1()
}
withSpecificTypes(NoOpAction(), state: nil, function: reducerFunction)
XCTAssertTrue(called)
}
/**
it doesn't call if source type can't be casted to function signature type
*/
func testDoesntCallIfCastFails() {
var called = false
let reducerFunction: (Action, AppState1?) -> AppState1 = { action, state in
called = true
return state ?? AppState1()
}
withSpecificTypes(NoOpAction(), state: AppState2(), function: reducerFunction)
XCTAssertFalse(called)
}
}