Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Latest commit

 

History

History
233 lines (158 loc) · 5.89 KB

reactivetest.md

File metadata and controls

233 lines (158 loc) · 5.89 KB

Rx.ReactiveTest class

This class contains test utility methods such as create notifications for testing purposes.

Location

  • rx.testing.js

ReactiveTest Class Methods

ReactiveTest Class Fields

ReactiveTest Class Methods

Rx.ReactiveTest.onCompleted(ticks)

#

Factory method for an OnCompleted notification record at a given time.

Arguments

  1. ticks (Number): Recorded virtual time the OnCompleted notification occurs.

Returns

(Recorded): OnCompleted notification.

Example

var onCompleted = Rx.ReactiveTest.onCompleted;

var scheduler = new Rx.TestScheduler();

var xs = scheduler.createHotObservable(
  onCompleted(260)
);

var res = scheduler.startScheduler(function () {
  return xs.map(function (x) { return x; });
});

// Write custom assertion
collectionAssert.assertEqual(res.messages, [
  onCompleted(260)
]);

Location

  • rx.testing.js

Rx.ReactiveTest.onError(ticks, exception)

#

Factory method for an OnError notification record at a given time with a given error.

Arguments

  1. ticks (Number): Recorded virtual time the OnError notification occurs.
  2. exception (Error | Function): Recorded exception stored in the OnError notification or a predicate

Returns

(Recorded): Recorded OnError notification.

Example

var ex = new Error('woops');

var onError = Rx.ReactiveTest.onError;

var scheduler = new Rx.TestScheduler();

var xs = scheduler.createHotObservable(
    onError(201, ex)
);

var res = scheduler.startScheduler(function () {
  return xs.map(function (x) { return x; });
});

// Write custom assertion
collectionAssert.assertEqual(res.messages, [

  // Using a predicate
  onError(201, function (e) { return e.message === 'woops'; })
]);

Location

  • rx.testing.js

Rx.ReactiveTest.onNext(ticks, value)

#

Factory method for an OnNext notification record at a given time with a given error.

Arguments

  1. ticks (Number): Recorded virtual time the OnNext notification occurs.
  2. value (Any | Function): Recorded exception stored in the OnNext notification or a predicate

Returns

(Recorded): Recorded OnNext notification.

Example

var onNext = Rx.ReactiveTest.onNext;

var scheduler = new Rx.TestScheduler();

var xs = scheduler.createHotObservable(
    onNext(201, 42)
);

var res = scheduler.startScheduler(function () {
  return xs.map(function (x) { return x; });
});

// Write custom assertion
collectionAssert.assertEqual(res.messages, [

  // Using a predicate
  onNext(201, function (x) { return x === 42; })
]);

Location

  • rx.testing.js

ReactiveTest Class Fields

Rx.ReactiveTest.created

#

Default virtual time used for creation of observable sequences in unit tests. This has a value of 100.

Example

var scheduler = new Rx.TestScheduler();

var xs = scheduler.createHotObservable(
  Rx.ReactiveTest.onNext(201, 42),
  Rx.ReactiveTest.onNext(202, 56),
  Rx.ReactiveTest.onCompleted(203)
);

var res = scheduler.startScheduler(
  function () { return xs.map(function (x) { return x; })},
  Rx.ReactiveTest.created,
  Rx.ReactiveTest.subscribed,
  Rx.ReactiveTest.disposed
);

Location

  • rx.testing.js

Rx.ReactiveTest.disposed

#

Default virtual time used to dispose subscriptions in unit tests. This has a value of 1000.

Example

var scheduler = new Rx.TestScheduler();

var xs = scheduler.createHotObservable(
  Rx.ReactiveTest.onNext(201, 42),
  Rx.ReactiveTest.onNext(202, 56),
  Rx.ReactiveTest.onCompleted(203)
);

var res = scheduler.startScheduler(
  function () { return xs.map(function (x) { return x; })},
  {
    created: Rx.ReactiveTest.created,
    subscribed: Rx.ReactiveTest.subscribed,
    disposed: Rx.ReactiveTest.disposed
  }
);

Location

  • rx.testing.js

Rx.ReactiveTest.subscribed

#

Default virtual time used to subscribe to observable sequences in unit tests. This has a value of 200.

Example

var scheduler = new Rx.TestScheduler();

var xs = scheduler.createHotObservable(
  Rx.ReactiveTest.onNext(201, 42),
  Rx.ReactiveTest.onNext(202, 56),
  Rx.ReactiveTest.onCompleted(203)
);

var res = scheduler.startScheduler(
  function () { return xs.map(function (x) { return x; })}
);

Location

  • rx.testing.js