@parity/light.js
Version:
A high-level reactive JS library optimized for light clients
59 lines (58 loc) • 2.42 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 Api = require("@parity/api");
var isObservable_1 = require("../utils/isObservable");
var mockApi_1 = require("../utils/testHelpers/mockApi");
var rpc_1 = require("./rpc");
var api_1 = require("../api");
/*
* Mock the Api of the RPC dependencies' observables
*
* Needed because the RPC observable passes the provider of the api (set e.g.
* using setApi) to its RPC dependencies (e.g. frequency), which in turn call
* createApiFromProvider to create a new Api based on that provider. Even if
* the Api of the initial RPC observable is mocked, the Api from the dependency
* observable isn't mocked as it is created from the provider, using @parity/api
* Since we want to mock the Api and not just the provider for the dependencies,
* we have to mock @parity/api
* */
jest.mock('@parity/api');
Api.mockImplementation(function () { return mockApi_1.resolveApi(); });
/**
* Helper function to make basic tests for RpcObservables.
*
* @ignore
*/
var testRpc = function (name, rpc$) {
return describe(name + " rpc", function () {
beforeEach(function () {
// Mock the Api of the RPC observables (however, doesn't mock the Api of
// their dependencies' observables)
api_1.setApi(mockApi_1.resolveApi());
});
var options = name === 'post$' ? { passphrase: 'passphrase' } : {};
it('should be a function', function () {
expect(typeof rpc$).toBe('function');
});
it('should return an Observable', function () {
expect(isObservable_1.default(rpc$({}, options))).toBe(true);
});
it('result Observable should be subscribable', function () {
expect(function () { return rpc$({}, options).subscribe(); }).not.toThrow();
});
it('result Observable should return values', function (done) {
rpc$({}, options).subscribe(function (data) {
expect(data).not.toBeNull();
done();
});
});
// Memoization tests don't concern post$
if (name === 'post$' || name === 'postRaw$') {
}
});
};
Object.keys(rpc_1.default).forEach(function (key) { return testRpc(key, rpc_1.default[key]); });
;