Closed
Description
EDIT Repository to reproduce: https://github.com/jozsi/bug-jest-mongoose
Using the latest version of Jest (19.0.2
) and Mongoose (4.8.5
), the following code is breaking when ran by jest:
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
email: {
type: String,
unique: true,
},
});
const User = mongoose.model('User', userSchema);
User.on('index', function(err) {
console.log('Index creation errored?', err);
});
mongoose.connect('localhost/test123');
Expected result (when ran by Node.js (7.6.0
)):
$ node test.js
Index creation errored? undefined
Actual result (when ran by Jest):
$ ./node_modules/.bin/jest --no-cache test.js
FAIL ./test.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (node_modules/jest/node_modules/jest-cli/build/TestRunner.js:192:18)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 1.277s
Ran all test suites matching "test.js".
console.log test.js:13
Index creation errored? Error {
name: 'MongoError',
message: 'Index keys cannot be empty.',
ok: 0,
errmsg: 'Index keys cannot be empty.',
code: 67,
codeName: 'CannotCreateIndex' }
I am using the default jest configuration (=> automocking is disabled).
Related: jestjs/jest#3045