Skip to content

Commit

Permalink
test(schema): repro #7803
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jul 7, 2019
1 parent 9651ba7 commit 82442da
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2062,4 +2062,23 @@ describe('schema', function() {
assert.strictEqual(testSchema.pathType('subpaths.list.0.options'),
'adhocOrUndefined');
});

it('supports pre(Array, Function) and post(Array, Function) (gh-7803)', function() {
const schema = Schema({ name: String });
schema.pre(['save', 'remove'], testMiddleware);
function testMiddleware() {
console.log('foo');
}

assert.equal(schema.s.hooks._pres.get('save').length, 1);
assert.equal(schema.s.hooks._pres.get('save')[0].fn, testMiddleware);
assert.equal(schema.s.hooks._pres.get('remove').length, 1);
assert.equal(schema.s.hooks._pres.get('remove')[0].fn, testMiddleware);

schema.post(['save', 'remove'], testMiddleware);
assert.equal(schema.s.hooks._posts.get('save').length, 1);
assert.equal(schema.s.hooks._posts.get('save')[0].fn, testMiddleware);
assert.equal(schema.s.hooks._posts.get('remove').length, 1);
assert.equal(schema.s.hooks._posts.get('remove')[0].fn, testMiddleware);
});
});

0 comments on commit 82442da

Please sign in to comment.