Swiftpack.co - DezorkIT/TestSubscriber as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by DezorkIT.
DezorkIT/TestSubscriber 0.1.1
Package for testing publishers in Combine framework.
⭐️ 0
🕓 1 week ago
iOS macOS
.package(url: "https://github.com/DezorkIT/TestSubscriber.git", from: "0.1.1")

TestSubscriber

Package for testing publishers in Combine framework.

Usage

To start you need to create TestSubscriber and subscribe your publisher to it

  let subject = PassthroughSubject<Int, TestError>()
  let subscriber = TestSubscriber<Int, TestError>()
  subject.subscribe(subscriber)

Assertion works by throwing exceptions, your tests methods should be declared with throws keyword.

Examples

Value assertion:

  subject.send(1)
  subject.send(2)
  subject.send(completion: .finished)

  try subscriber
      .assertValues(1,2)

Error assertion:

  subject.send(completion: .failure(.known))

  try subscriber
      .assertError(.known)

If your publisher is a subject you have to:

call finish on it

  subject.send(completion: .finished)

or failure

  subject.send(completion: .failure(.known))

or call unsubscribe method declared in TestSubscriber

  try subscriber
    .assertNoIntrecationsResult()
    .unsubscribe()

You can find more examples in test directory

Installation

  1. Select File menu > Add Packages...
  2. Enter "https://github.com/DezorkIT/TestSubscriber" into the package repository URL text field

GitHub

link
Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

0.1.1
1 week ago

fixed demand swift version lowered to 5.3

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics