web3.js/test/method.formatOutput.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-03-22 19:48:25 +01:00
var chai = require('chai');
var assert = chai.assert;
var Method = require('../packages/web3-core-method');
2015-03-22 19:48:25 +01:00
2015-03-25 22:17:35 +01:00
describe('lib/web3/method', function () {
2015-03-22 19:48:25 +01:00
describe('formatOutput', function () {
it('should format plain output', function () {
2015-03-22 19:48:25 +01:00
// given
var formatter = function (arg) {
return arg + '*';
};
var method = new Method({
name: 'something', call: 'eth_something',
outputFormatter: formatter
});
var args = '1';
var expectedArgs = '1*';
// when
var result = method.formatOutput(args);
// then
assert.deepEqual(result, expectedArgs);
});
it('should format plain output if array', function () {
// given
var formatter = function (arg) {
return arg + '*';
};
var method = new Method({
name: 'something', call: 'eth_something',
outputFormatter: formatter
});
var args = '1';
var expectedArgs = ['1*', '1*'];
// when
var result = method.formatOutput([args, args]);
// then
assert.deepEqual(result, expectedArgs);
});
it('should format output arrays with the same formatter', function () {
// given
var formatter = function (arg) {
return arg + '*';
2015-03-22 19:48:25 +01:00
};
2015-03-22 19:48:25 +01:00
var method = new Method({
name: 'something', call: 'eth_something',
2015-03-22 19:48:25 +01:00
outputFormatter: formatter
});
var args = ['1','2','3'];
var expectedArgs = ['1*', '2*', '3*'];
// when
var result = method.formatOutput(args);
// then
assert.deepEqual(result, expectedArgs);
});
2015-03-22 19:48:25 +01:00
it('should do nothing if there is no formatter', function () {
// given
var method = new Method({name: 'something', call: 'eth_something'});
2015-03-22 19:48:25 +01:00
var args = [1,2,3];
// when
var result = method.formatOutput(args);
2015-03-22 19:48:25 +01:00
// then
assert.deepEqual(result, args);
});
});
});