{"action":"closed","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/2217","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/2217/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/2217/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/2217/events","html_url":"https://github.com/Automattic/mongoose/issues/2217","id":39040498,"number":2217,"title":"mocha timeout when using async schema validator","user":{"login":"danielkrainas","id":2432851,"avatar_url":"https://avatars0.githubusercontent.com/u/2432851?v=4","gravatar_id":"","url":"https://api.github.com/users/danielkrainas","html_url":"https://github.com/danielkrainas","followers_url":"https://api.github.com/users/danielkrainas/followers","following_url":"https://api.github.com/users/danielkrainas/following{/other_user}","gists_url":"https://api.github.com/users/danielkrainas/gists{/gist_id}","starred_url":"https://api.github.com/users/danielkrainas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielkrainas/subscriptions","organizations_url":"https://api.github.com/users/danielkrainas/orgs","repos_url":"https://api.github.com/users/danielkrainas/repos","events_url":"https://api.github.com/users/danielkrainas/events{/privacy}","received_events_url":"https://api.github.com/users/danielkrainas/received_events","type":"User","site_admin":false},"labels":[{"id":144307,"url":"https://api.github.com/repos/Automattic/mongoose/labels/bug?","name":"bug?","color":"d7e102","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2014-07-29T22:00:20Z","updated_at":"2017-11-11T02:39:08Z","closed_at":"2017-11-11T02:39:08Z","author_association":"NONE","body":"I'm trying to set some tests up for my model and making use of mockgoose@1.10.2 on top of mongoose@3.8.9. My problem is that when I switch to an async validation on my schema, any related mocha tests simply timeout with a lackluster stacktrace:\n\n![image](https://cloud.githubusercontent.com/assets/2432851/3742513/548bc458-176a-11e4-8c66-18d06684d092.png)\n\nWhen I switch back to synchronous validation, it still fails, but not from a timeout. Instead, it will fail because it seems like mongoose doesn't respect the return from the validator which I've figured out does return false as it should. I'm not sure if this is a bug, if it's something I'm doing wrong, or if I'm misunderstanding the usage condition.\n\nHere is the test:\n\n``` js\n        it('should fail to save user with blank name', function(done) {\n            user.name = '';\n            user.save(function(err) {\n                should.exist(err);\n                done();\n            });\n        });\n```\n\nAnd here is the validator from the schema (async version replaces return with a call to `ok`, passing the same expression):\n\n``` js\n    UserSchema.path('name').validate(function(name, ok) {\n        console.log({ name: name, validation: (typeof name === 'string' && name.length > 0), ok: ok });\n        if(!this.provider) return true;\n\n        return (typeof name === 'string' && name.length > 0);\n    }, 'Name cannot be blank');\n```\n"}}
{"actor":{"display_login":"vkarpov15"}}