{"id":13847225,"url":"https://github.com/devniel/nestjs-typeorm-testing","last_synced_at":"2025-05-05T11:32:34.011Z","repository":{"id":40793814,"uuid":"245899940","full_name":"devniel/nestjs-typeorm-testing","owner":"devniel","description":"Typeorm Testing module for NestJS, with this module you don't need an access to DB to test the BeforeInsert hook of typeorm entities.","archived":false,"fork":false,"pushed_at":"2023-03-04T06:24:06.000Z","size":1694,"stargazers_count":16,"open_issues_count":9,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T10:24:48.370Z","etag":null,"topics":["fake","mock","nestjs","testing","typeorm"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devniel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-03-08T22:44:27.000Z","updated_at":"2024-07-11T14:35:19.000Z","dependencies_parsed_at":"2024-01-15T20:49:02.337Z","dependency_job_id":"9f7d247f-9d80-47dd-9e90-88dfc2a296f4","html_url":"https://github.com/devniel/nestjs-typeorm-testing","commit_stats":{"total_commits":35,"total_committers":3,"mean_commits":"11.666666666666666","dds":0.4,"last_synced_commit":"37076d44f7903d9e5046d752ab7cb5d8137a5834"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnestjs-typeorm-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnestjs-typeorm-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnestjs-typeorm-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnestjs-typeorm-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devniel","download_url":"https://codeload.github.com/devniel/nestjs-typeorm-testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252489222,"owners_count":21756287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fake","mock","nestjs","testing","typeorm"],"created_at":"2024-08-04T18:01:13.796Z","updated_at":"2025-05-05T11:32:33.652Z","avatar_url":"https://github.com/devniel.png","language":"TypeScript","readme":"Typeorm Testing module for NestJS, with this module you don't need an access to DB to test the BeforeInsert hook of typeorm entities.\n\nBased on https://github.com/typeorm/typeorm/issues/1267#issuecomment-456200490 and some debugging/reading of the typeorm and @nestjs/typeorm flow.\n\nCreated with https://github.com/nestjsplus/nestjs-package-starter.\n\n## Install:\n```shell\nnpm install --save-dev @devniel/nestjs-typeorm-testing\n```\n\n## Example of use:\n\nInvoke `TypeOrmTestModule.forTest` and pass as an argument an array with the entities used in the app.\n\nBy now it will create fake queries against a fake postgresql database connection.\n\nIf your entity (e.g. `User`) has hooks like `@BeforeInsert()`, the testing module will invoke it just like a regular typeorm module when using the injected repository in the proper services.\n\n```ts\nimport { TypeOrmTestModule } from '@devniel/nestjs-typeorm-testing';\n\nconst module: TestingModule = await Test.createTestingModule({\n  controllers: [AuthResolver],\n  imports: [TypeOrmTestModule.forTest([User])],\n  providers: [\n    AuthService,\n    UsersService,\n    {\n      provide: JwtService,\n      useValue: jwtServiceMock,\n    },\n    {\n      provide: RedisService,\n      useValue: redisServiceMock,\n    },\n  ],\n}).compile();\n```\n\n### Custom connection name\n\nTo provide a custom connection name, then set the first argument of `forTest` as an options object.\n\n```ts\nimport { TypeOrmTestModule } from '@devniel/nestjs-typeorm-testing';\n\nconst module: TestingModule = await Test.createTestingModule({\n  controllers: [AuthResolver],\n  imports: [TypeOrmTestModule.forTest({\n    entities: [User],\n    name: 'default2'\n  })],\n  providers: [\n    AuthService,\n    UsersService,\n    {\n      provide: JwtService,\n      useValue: jwtServiceMock,\n    },\n    {\n      provide: RedisService,\n      useValue: redisServiceMock,\n    },\n  ],\n}).compile();\n```\n\n### Getting the fake connection\nYou can get the created fake connection and check its properties or close it.\n```ts\nimport { TypeOrmTestModule } from '@devniel/nestjs-typeorm-testing';\nimport { getConnectionToken } from '@nestjs/typeorm';\n\nconst module: TestingModule = await Test.createTestingModule({\n  controllers: [AuthResolver],\n  imports: [TypeOrmTestModule.forTest({\n    entities: [User],\n    name: 'default2'\n  })]\n}).compile();\nconst connection = module.get(getConnectionToken('default2'));\nconnection.close(); // module.close() also closes the connection\n```\n\n## Todo:\n\n- Capture queries.\n- Create utils to override the repositories with ease.\n\n## License\n\nLicensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevniel%2Fnestjs-typeorm-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevniel%2Fnestjs-typeorm-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevniel%2Fnestjs-typeorm-testing/lists"}