Fix caching for different params (#822)

This commit is contained in:
Amaury Martiny
2019-04-03 12:46:33 +02:00
committed by Jaco Greeff
parent 761cf6d52a
commit f20727b46d
2 changed files with 29 additions and 11 deletions
+12
View File
@@ -3,7 +3,9 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { Observable } from 'rxjs';
import testingPairs from '@polkadot/keyring/testingPairs';
import { RpcInterface$Section } from '@polkadot/rpc-core/types';
import { AccountId } from '@polkadot/types';
jest.mock('@polkadot/rpc-provider/ws', () => class {
isConnected = () => true;
@@ -16,6 +18,7 @@ import RpcRx from '.';
describe('createCachedObservable', () => {
let api: RpcRx;
let creator: (...params: Array<any>) => Observable<any>;
const keyring = testingPairs();
let section: RpcInterface$Section;
beforeEach(() => {
@@ -51,6 +54,15 @@ describe('createCachedObservable', () => {
).toBe(observable1);
});
it('creates a single observable (multiple calls, different arguments that should be cached together)', () => {
const observable1 = creator(keyring.alice.address());
const observable2 = creator(new AccountId(keyring.alice.address()));
expect(
observable2
).toBe(observable1);
});
it('creates multiple observables for different values', () => {
const observable1 = creator(123);
const observable2 = creator(456);