From ad34fd191daa7d29f4992273209d0eddacd5ac02 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Tue, 11 Mar 2014 10:21:26 -0300 Subject: [PATCH] starting Address idiom changes --- Address.js | 4 +++- test/test.Address.js | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Address.js b/Address.js index f274333fc..ad032be0b 100644 --- a/Address.js +++ b/Address.js @@ -10,10 +10,12 @@ Address.parent = parent; parent.applyEncodingsTo(Address); Address.prototype.validate = function() { + var answer; this.doAsBinary(function() { Address.super(this, 'validate', arguments); - if(this.data.length !== 21) throw new Error('invalid data length'); + answer = (this.data.length === 21); }); + return answer; }; module.exports = require('soop')(Address); diff --git a/test/test.Address.js b/test/test.Address.js index 758440e0a..11b939b63 100644 --- a/test/test.Address.js +++ b/test/test.Address.js @@ -26,7 +26,11 @@ describe('Address', function() { var b = new Address('11111111111111111111111111122222234'); a.validate.bind(a).should.not.throw(Error); m.validate.bind(m).should.not.throw(Error); - b.validate.bind(b).should.throw(Error); + b.validate.bind(b).should.not.throw(Error); + + a.validate().should.equal(true); + m.validate().should.equal(true); + b.validate().should.equal(false); }); });