var chai = require('chai'); var assert = chai.assert; var Method = require('../lib/web3/method'); var utils = require('../lib/utils/utils'); describe('lib/web3/method', function () { describe('attachToObject', function () { it('attach simple function to an object', function () { // given var method = new Method({ name: 'hello' }); var object = {}; var func = function () { return 1; }; // when method.attachToObject(object, func); // then assert.equal(utils.isFunction(object.hello), true); assert.equal(object.hello(), 1); }); it('attach nested function to an object', function () { // given var method = new Method({ name: 'hello.world' }); var object = {}; var func = function () { return 1; }; // when method.attachToObject(object, func); // then assert.equal(utils.isObject(object.hello), true); assert.equal(utils.isFunction(object.hello.world), true); assert.equal(object.hello.world(), 1); }); }); });