Type | RxJava | ReactiveSwift | Combine |
---|---|---|---|
properties | Observable<T>, where Observable is often backed by a BehaviorSubject | Property<T>, where it wraps a MutableProperty | CurrentValueSubject or @Published |
retrieving values | Single<T> | SignalProducer<T> | Publisher<T, Error>, or Deferred + Future |
modifying state | Completable | SignalProducer<Void, Error> | Publisher<T, Error> |
This file contains 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
// Define the mock | |
single<IMatchApi> { | |
mockk<IMatchApi>(relaxed = true) { | |
every { getMatchStack() } returns Single.just(defaultMatchStack()) | |
} | |
} | |
// inject into tests | |
val matchApi: IMatchApi by inject() |
This file contains 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
// Define the mock | |
class MatchApiFixture: PSSMatchApiImplementing { | |
public var getMatchStackValue: Result<PSSMatchStack, Error> = .success(PSSMatchStack.fixture!) | |
func getMatchStack() -> SignalProducer<PSSMatchStack, Error> { | |
return SignalProducer(getMatchStackValue) | |
} | |
} | |
// Inject into tests | |
let matchApi = (container.resolve(PSSMatchApiImplementing.self)! as! MatchApiFixture) |
This file contains 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
context("given instruction cards should be shown") { | |
var testObs: TestObserver<PSSMatchViewModel.Event, Never>! | |
beforeEach { | |
testObs = TestObserver<PSSMatchViewModel.Event, Never>() | |
viewModel.events.signal.observe(testObs.observer) | |
} | |
it("then swipe right card shown first") { | |
guard case .started(let context) = viewModel.state.value else { |
This file contains 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
@Nested | |
@DisplayName("given instruction cards should be shown") | |
inner class InstructionCards { | |
@BeforeEach | |
fun setup() { | |
matchViewModel.startButtonTapped() | |
} | |
@Test | |
fun `then swipe right card shown first`() { |
This file contains 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
class InstantExecutorExtension : BeforeEachCallback, AfterEachCallback { | |
override fun beforeEach(context: ExtensionContext?) { | |
ArchTaskExecutor.getInstance() | |
.setDelegate(object : TaskExecutor() { | |
override fun executeOnDiskIO(runnable: Runnable) = runnable.run() | |
override fun postToMainThread(runnable: Runnable) = runnable.run() | |
override fun isMainThread(): Boolean = true | |
}) |
This file contains 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
context("given I flag someone") { | |
var testObs: TestObserver<PSSMatchViewModel.Event, Never>! | |
var targetProfile: PSSProfile! | |
beforeEach { | |
testObs = TestObserver<PSSMatchViewModel.Event, Never>() | |
viewModel.events.signal.observe(testObs.observer) | |
for _ in 0..<instructionCardsNum { | |
viewModel.swipe(rating: PSSMatchRating.interested) |
This file contains 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
@Nested | |
@DisplayName("given I flag someone") | |
inner class FlagSomeone { | |
lateinit var testObserver: TestObserver<MatchEvent> | |
lateinit var targetProfile: Profile | |
@BeforeEach | |
fun setup() { | |
testObserver = matchViewModel.events.test() |
This file contains 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
static func mapError(apiError: Error) -> PSSFreeTrialError { | |
if let apiError = apiError as? PSSApiError { | |
switch apiError.statusCode { | |
case Int(HTTP_RESPONSE_BAD_REQUEST): | |
return PSSFreeTrialError.cannotBeActivated |
Platform | GET | POST/DELETE |
---|---|---|
iOS | SignalProducer<T, TError> or AnyPublisher<T, TError> | SignalProducer<Void, Error> or AnyPublisher<Void, TError> |
Android | Single | Completable |