Cannot inject the dependency at position #0 of
See original GitHub issueI try create a test but this error persist. Maybe any incompatibility? ( On Insomnia all works fine.) When I use .get(‘/products’) always returns code 404 page not found.
at src/modules/session/Session.spec.ts:12:29 at step (src/modules/session/Session.spec.ts:33:23) at Object.next (src/modules/session/Session.spec.ts:14:53) at fulfilled (src/modules/session/Session.spec.ts:5:58)
console.log Error: Cannot inject the dependency at position #0 of “CreateSession” constructor. Reason: No repository for “User” was found. Looks like this entity is not registered in current “default” connection? at C:\Users\gleys\projects\jejconceito\node_modules\tsyringe\dist\cjs\dependency-container.js:209:23 at Array.map (<anonymous>) at InternalDependencyContainer.construct (C:\Users\gleys\projects\jejconceito\node_modules\tsyringe\dist\cjs\dependency-container.js:195:34) at InternalDependencyContainer.resolve (C:\Users\gleys\projects\jejconceito\node_modules\tsyringe\dist\cjs\dependency-container.js:81:25) at SessionController.<anonymous> (C:\Users\gleys\projects\jejconceito\src\modules\session\controller\SessionController.ts:9:44) at step (C:\Users\gleys\projects\jejconceito\src\modules\session\controller\SessionController.ts:33:23) at Object.next (C:\Users\gleys\projects\jejconceito\src\modules\session\controller\SessionController.ts:14:53) at C:\Users\gleys\projects\jejconceito\src\modules\session\controller\SessionController.ts:8:71 at new Promise (<anonymous>)
This is my code:
/* eslint-disable @typescript-eslint/camelcase */
import '@shared/infra/typeorm';
import request from 'supertest';
import app from '@shared/infra/http/app';
describe('Authentication', () => {
it('should authenticate with valid credentials', async () => {
const response = await request(app).post('/session').send({
login: 'email',
password: 'sss',
});
expect(response.status).toBe(200);
});
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:14
Top GitHub Comments
e necessario importar o container no primeiro arquivo da sua aplicacao
ex: import “./shared/container”
The error happened because connection not initialized yet so create a async await connection and now works fine.