Я выполняю модульное тестирование в проекте с Keystone , но всегда выдает ошибку при тестировании:
an all test suites.
/Project/node_modules/mongodb/lib/mongo_client.js:433
throw err
^
TypeError: require(...) is not a function
at /Project/node_modules/keystone/lib/core/start.js:64:44
at /Project/node_modules/async/dist/async.js:3880:24
at eachOfArrayLike (/Project/node_modules/async/dist/async.js:1069:9)
at eachOf (/Project/node_modules/async/dist/async.js:1117:5)
at _parallel (/Project/node_modules/async/dist/async.js:3879:5)
at Object.parallelLimit [as parallel] (/Project/node_modules/async/dist/async.js:3962:5)
at /Project/node_modules/keystone/lib/core/start.js:60:9
at connected (/Project/node_modules/keystone/lib/core/openDatabaseConnection.js:78:5)
at NativeConnection.<anonymous> (/Project/node_modules/keystone/lib/core/openDatabaseConnection.js:85:4)
at Object.onceWrapper (events.js:273:13)
at NativeConnection.emit (events.js:182:13)
at /Project/node_modules/mongoose/lib/connection.js:860:13
at connectCallback (/Project/node_modules/mongodb/lib/mongo_client.js:527:5)
at /Project/node_modules/mongodb/lib/mongo_client.js:430:11
at process._tickCallback (internal/process/next_tick.js:61:11)
npm ERR! Test failed. See above for more details.
Я уже пытался использовать "import {init, start, mongoose}из "краеугольного камня"; "вместо этого, используя jest async () и ожидайте.Я тоже запускаю "jest --clearCache"Версия Jest: "Jest": "^ 24.3.1"
Мой .babelrc:
{
"presets": [
["@babel/preset-env",
{"targets": {
"node": "current"
}}
],
"@babel/preset-react"
]
}
test.js:
const Keystone = require('keystone');
beforeAll( done => {
Keystone.init({
'name': 'Keystone CMS',
'cookie secret': 'My_Biscuit',
});
Keystone.start();
done();
})
describe('Test Keystone CMS own features', () => {
test('Keystone connects to MongoDB', (done) => {
expect(Keystone.mongoose.connections._listening).toBeTruthy;
done();
});
});
Затем я его раскроюпроверить мангуст