Browse Source

starting Address idiom changes

patch-2
Manuel Araoz 11 years ago
parent
commit
ad34fd191d
  1. 4
      Address.js
  2. 6
      test/test.Address.js

4
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);

6
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);
});
});

Loading…
Cancel
Save