json-rpc-protocol
Version:
JSON-RPC 2 protocol messages parsing and formatting
59 lines • 2.05 kB
JavaScript
;
/* eslint-env jest */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var errors_1 = require("./errors");
var format = __importStar(require("./format"));
var fromJson = JSON.parse;
// ===================================================================
describe('format', function () {
it('.error()', function () {
expect(fromJson(format.error(null, new errors_1.JsonRpcError('foo', 42)))).toEqual({
error: {
code: 42,
message: 'foo'
},
id: null,
jsonrpc: '2.0'
});
});
it('.notification()', function () {
expect(fromJson(format.notification('foo'))).toEqual({
jsonrpc: '2.0',
method: 'foo'
});
});
it('.request()', function () {
expect(fromJson(format.request(0, 'foo'))).toEqual({
id: 0,
jsonrpc: '2.0',
method: 'foo'
});
});
it('.response()', function () {
expect(fromJson(format.response(1, 'foo'))).toEqual({
id: 1,
jsonrpc: '2.0',
result: 'foo'
});
});
});
//# sourceMappingURL=format.spec.js.map