Skip to content

Commit

Permalink
strict structs with additional methods should not throw on updating, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Dec 24, 2016
1 parent bdd7112 commit 75f5f69
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
**Note**: Gaps between patch versions are faulty/broken releases.
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

# v3.2.16

- **Bug Fix**
- strict structs with additional methods should not throw on updating, fix #267 (@gcanti)

# v3.2.15

- **New Feature**
Expand Down
6 changes: 4 additions & 2 deletions lib/assign.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function assign(x, y) {
for (var k in y) {
x[k] = y[k];
if (y.hasOwnProperty(k)) {
x[k] = y[k];
}
}
return x;
}

module.exports = assign;
module.exports = assign;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tcomb",
"version": "3.2.15",
"version": "3.2.16",
"description": "Type checking and DDD for JavaScript",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions test/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ describe('t.update(instance, patch)', function () {
y: t.Number
});

it('strict structs with additional methods should not throw on updating', function () {
var Rectangle = t.struct({
width: t.Number,
height: t.Number
}, {strict: true});

Rectangle.prototype.getArea = function () {
return this.width * this.height;
};

var r = Rectangle({width: 10, height: 10});
assert.equal(Rectangle.update(r, {width: {$set: 20}}).width, 20);
});

it('should throw if patch is invalid', function () {
throwsWithMessage(function () {
t.update({});
Expand Down

0 comments on commit 75f5f69

Please sign in to comment.