[ ] Regression
[ x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
I get the following error when running tests using mockgoose:
(node:10262) UnhandledPromiseRejectionWarning: Error [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
at new ClientRequest (_http_client.js:131:11)
at request (https.js:245:10)
at Object.get (https.js:249:15)
at /development/node/project2/node_modules/mongodb-download/src/mongodb-download.ts:312:31
at new Promise (
at MongoDBDownload.httpDownload (/development/node/project2/node_modules/mongodb-download/src/mongodb-download.ts:309:12)
at /development/node/project2/node_modules/mongodb-download/src/mongodb-download.ts:174:18
at
(node:10262) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 24)
tests that don't require me to connect to DB will succeed. Ones that need DB connection will fail. (both throw these errors).
Be able to use mockgoose for tests
Application runs perfectly, it seems that once it starts the application going in to the IF statement in the following code from databaseProvider, it goes wrong
useFactory: async () => {
(mongoose as any).Promise = global.Promise;
if (process.env.NODE_ENV !== 'test') {
// when running tests, it gets here, tested with console.log
const mockgoose = new Mockgoose(mongoose);
mockgoose.helper.setDbVersion('3.6.0');
mockgoose.prepareStorage()
.then(async () => {
await mongoose.connect('mongodb://localhost:27017/myAppTest', {
useMongoClient: true
});
}).catch(()=>{ console.log('ERR! Unable to prepare test database')});
} else {
await mongoose.connect(process.env.dbUrl ? process.env.dbUrl : 'mongodb://localhost:27017/myApp', {
useMongoClient: true
});
}
return mongoose;
}
Nest version: 4.5.2
For Tooling issues:
- Node version: 9.3.0
- Platform: Mac
Others:
Hi @MiVvlt,
Thanks for reporting. cc @vladotesanovic
@MiVvlt @kamilmysliwiec
Yes there is problem with Mockgoose library,
@MiVvlt
You will need to change package in package.json and import in provider.database.ts
from:
mockgoose to mockgoose-fix
"mockgoose-fix": "^7.3.5",
and
import { Mockgoose } from 'mockgoose-fix';
I will update docs.nestjs.com and example in next days.
PR is merged already 馃檪
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.