Skip to content

Commit

Permalink
test: repro Automattic#9163
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanHafez committed Jun 25, 2020
1 parent e5617db commit ea7ecf3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8975,4 +8975,26 @@ describe('document', function() {
const axl = new Person({ fullName: 'Axl Rose' });
assert.equal(axl.fullName, 'Axl Rose');
});

it('throws an error when `transform` returns a promise (gh-9163)', function() {
const userSchema = new Schema({
name: {
type: String,
transform: function() {
return new Promise(() => {});
}
}
});

const User = mongoose.model('User', userSchema);

const user = new User({ name: 'Hafez' });
assert.throws(function() {
user.toJSON();
}, /`transform` option has to be synchronous, but is returning a promise on path `name`./);

assert.throws(function() {
user.toObject();
}, /`transform` option has to be synchronous, but is returning a promise on path `name`./);
});
});

0 comments on commit ea7ecf3

Please sign in to comment.