GithubHelp home page GithubHelp logo

driesschulten / rxexpect Goto Github PK

View Code? Open in Web Editor NEW

This project forked from devxoul/rxexpect

0.0 2.0 0.0 54 KB

The RxSwift testing framework

License: MIT License

Ruby 3.04% Swift 92.01% Objective-C 4.95%

rxexpect's Introduction

RxExpect

Swift Build Status CocoaPods Carthage compatible

RxExpect is a testing framework for RxSwift.

Concept

Provide inputs then test outputs. This is an example code that tests map() operator multiplying the values by 2.

func testMultiply() {
  RxExpect("it should multiply values by 2") { test in
    let value = PublishSubject<Int>()
    let result = value.map { $0 * 2 }

    // provide inputs
    test.input(value, [
      next(100, 1),
      next(200, 2),
      next(300, 3),
      completed(400)
    ])
    
    // test output
    test.assert(result)
      .equal([
        next(2),
        next(4),
        next(6),
        completed(400)
      ])
  }
}

It would be easy to understand if you imagine the marble diagram.

time   --100-200-300-400 // virtual timeline
value  --1---2---3---|   // provide inputs
result --2---4---6---|   // test these values

This is more complicated example.

final class ArticleDetailViewModelTests: RxTestCase {

  func testLikeButtonSelected() {
    RxExpect("like button should become selected when like button tapped") { test in
      let viewModel = ArticleDetailViewModel()

      // providing an user input: user tapped like button
      test.input(viewModel.likeButtonDidTap, [
        next(100),
      ])

      // test output: like button become selected
      test.assert(viewModel.isLikeButtonSelected)
        .filterNext()
        .since(100)
        .equal([true])
    }
    
    RxExpect("like button should become unselected when like button tapped") { test in
      let viewModel = ArticleDetailViewModel()

      // providing an user input: user tapped like button
      test.input(viewModel.likeButtonDidTap, [
        next(100),
      ])

      // test output: like button become selected
      test.assert(viewModel.isLikeButtonSelected)
        .filterNext()
        .since(100)
        .equal([false])
    }
  }

}

Examples

APIs

Providing Inputs

  • input(observer, events)
  • input(variable, events)

Start Assertion Chaining

  • assert(source)

Filtering Events

  • filterNext()
  • since(timeSince)
  • until(timeUntil)
  • within(timeRange)

Reversing Result

  • not()

Assertions

  • equal(expectedEvents)
  • isEmpty()
  • contains()

Installation

  • For iOS 8+ projects with CocoaPods:

    pod 'RxExpect', '~> 0.5'
  • For iOS 8+ projects with Carthage:

    github "devxoul/RxExpect" ~> 0.5
    

Development

$ git clone https://github.com/devxoul/RxExpect
$ cd RxExpect
$ carthage checkout --no-use-binaries
$ open RxExpect.xcworkspace

License

RxExpect is under MIT license. See the LICENSE file for more info.

rxexpect's People

Contributors

devxoul avatar

Watchers

Dries Schulten avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.