@parity/light.js
Version:
A high-level reactive JS library optimized for light clients
47 lines (46 loc) • 1.54 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 bignumber_js_1 = require("bignumber.js");
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var distinctValues_1 = require("./distinctValues");
// Observable that fires twice
var fireTwice$ = function () { return rxjs_1.of(0, 1); };
it('should fire twice if values are different', function (done) {
var numberOfTimesCalled = 0;
fireTwice$()
.pipe(operators_1.finalize(function () {
expect(numberOfTimesCalled).toEqual(2);
done();
}))
.subscribe(function () {
++numberOfTimesCalled;
});
});
/**
* Test that distinctValues work on a specific value.
*
* @param value - A value to test.
*/
var testValue = function (value, type) {
return it("should only fire once for " + type, function (done) {
var numberOfTimesCalled = 0;
fireTwice$()
.pipe(operators_1.mapTo(value), distinctValues_1.distinctValues(), operators_1.finalize(function () {
expect(numberOfTimesCalled).toEqual(1);
done();
}))
.subscribe(function () {
++numberOfTimesCalled;
});
});
};
testValue(2, 'number');
testValue('foo', 'string');
testValue({ foo: 'bar' }, 'object');
testValue(new bignumber_js_1.default(2), 'BigNumber');
testValue({ number: new bignumber_js_1.default(2) }, 'Block');
;