From 82442da20ae4014e478521472a261f0d175d585e Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sun, 7 Jul 2019 10:57:05 -0400 Subject: [PATCH] test(schema): repro #7803 --- test/schema.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/schema.test.js b/test/schema.test.js index 0e67f0b0cb8..c0724101fbe 100644 --- a/test/schema.test.js +++ b/test/schema.test.js @@ -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); + }); });