Skip to content

Commit

Permalink
test(document): repro #7196
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 2, 2018
1 parent d10274e commit 10837d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6393,4 +6393,33 @@ describe('document', function() {
err => { assert.ok(err.message.indexOf('Oops!') !== -1, err.message); }
);
});

it('runs setter only once when doing .set() underneath single nested (gh-7196)', function() {
let called = [];
const InnerSchema = new Schema({
name: String,
withSetter: {
type: String,
set: function(v) {
called.push(this);
return v;
}
}
});

const TestSchema = new Schema({ nested: InnerSchema });

const Model = db.model('gh7196', TestSchema);

const doc = new Model({ nested: { name: 'foo' } });

// Make sure setter only gets called once
called = [];
doc.set('nested.withSetter', 'bar');

assert.equal(called.length, 1);
assert.equal(called[0].name, 'foo');

return Promise.resolve();
});
});

0 comments on commit 10837d4

Please sign in to comment.