@parity/light.js
Version:
A high-level reactive JS library optimized for light clients
54 lines (53 loc) • 2.23 kB
JavaScript
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: MIT
Object.defineProperty(exports, "__esModule", { value: true });
var mockRpc_1 = require("../testHelpers/mockRpc");
var mockApi_1 = require("../testHelpers/mockApi");
var switchMapPromise_1 = require("./switchMapPromise");
it('should not error when the promise resolves with an error', function (done) {
mockRpc_1.default()
.pipe(switchMapPromise_1.switchMapPromise(mockApi_1.resolveApi({ error: 'bar' }).fake.method))
.subscribe(undefined, function () { return done.fail('It should not error.'); });
// If after 0.1s, nothing has been called, then our Observable has not fired
// any event, which is what we want
setTimeout(done, 100);
});
it('should not error when the promise rejects', function (done) {
mockRpc_1.default()
.pipe(switchMapPromise_1.switchMapPromise(mockApi_1.rejectApi().fake.method))
.subscribe(undefined, function () { return done.fail('It should not error.'); });
// If after 0.1s, nothing has been called, then our Observable has not fired
// any event, which is what we want
setTimeout(done, 100);
});
it('should fire an error when the promise resolves with an error', function (done) {
mockRpc_1.default()
.pipe(switchMapPromise_1.switchMapPromise(mockApi_1.rejectApi(new Error('boo')).fake.method, {
emitErrors: true
}))
.subscribe(undefined, function (err) {
expect(err).toEqual(new Error('boo'));
done();
});
});
it('should fire an error when the promise rejects', function (done) {
mockRpc_1.default()
.pipe(switchMapPromise_1.switchMapPromise(mockApi_1.rejectApi(new Error('boo')).fake.method, {
emitErrors: true
}))
.subscribe(undefined, function (err) {
expect(err).toEqual(new Error('boo'));
done();
});
});
it('should fire the correct value when the promise resolves', function (done) {
mockRpc_1.default()
.pipe(switchMapPromise_1.switchMapPromise(mockApi_1.resolveApi().fake.method))
.subscribe(function (data) {
expect(data).toBe('foo');
done();
});
});
;