{"id":20052621,"url":"https://github.com/devniel/example-typeorm-testing","last_synced_at":"2025-03-02T08:44:39.713Z","repository":{"id":43976173,"uuid":"247560950","full_name":"devniel/example-typeorm-testing","owner":"devniel","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-05T10:14:42.000Z","size":1188,"stargazers_count":2,"open_issues_count":14,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T21:09:56.374Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devniel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-15T22:16:11.000Z","updated_at":"2023-03-04T05:09:42.000Z","dependencies_parsed_at":"2023-02-04T00:32:34.017Z","dependency_job_id":null,"html_url":"https://github.com/devniel/example-typeorm-testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fexample-typeorm-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fexample-typeorm-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fexample-typeorm-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fexample-typeorm-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devniel","download_url":"https://codeload.github.com/devniel/example-typeorm-testing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241482061,"owners_count":19969847,"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":[],"created_at":"2024-11-13T12:18:33.101Z","updated_at":"2025-03-02T08:44:39.693Z","avatar_url":"https://github.com/devniel.png","language":"TypeScript","readme":"Added a test example using [nestjs-typeorm-testing](https://github.com/devniel/nestjs-typeorm-testing). By now, it's necessary to install.\n\n- @nestjs/typeorm\n- @nestjs/common\n- @nestjs/core\n- rxjs\n\nTodo:\n\n- Replace nestjs-typeorm-testing with a module only about typeorm to avoid installing the modules mentioned above.\n\n### Test example\n\nThe example is [here](https://github.com/devniel/example-typeorm-testing), you don't need even PostgreSQL installed on your machine to check if a hook on your entities is called or not.\n\n```ts\nimport {\n  createFakeConnection,\n  FakeConnection\n} from \"@devniel/nestjs-typeorm-testing\";\nimport { Category } from \"../entity/Category\";\nimport { Post } from \"../entity/Post\";\n\ndescribe(\"test\", () =\u003e {\n  let connection: FakeConnection;\n\n  beforeAll(async () =\u003e {\n    connection = await createFakeConnection({\n      name: \"test\",\n      type: \"postgres\",\n      entities: [Category, Post]\n    });\n  });\n\n  it(\"should invoke the before and after hooks before creating a new category\", async () =\u003e {\n    let category = new Category();\n    category.name = \"A new category\";\n    const spyBeforeInsert = spyOn(category, \"beforeInsert\");\n    const spyAfterInsert = spyOn(category, \"afterInsert\");\n    const repository = connection.getRepository(Category);\n    await repository.save(category);\n    console.log(`Category has been saved. Category is '${category.name}'`);\n    expect(spyBeforeInsert).toHaveBeenCalled();\n    expect(spyAfterInsert).toHaveBeenCalled();\n  });\n});\n```\n\n# Example how to use TypeORM with TypeScript\n\n1. clone repository \n2. run `npm i`\n3. edit `ormconfig.json` and change your database configuration (you can also change a database type, but don't forget to install specific database drivers)\n4. run `npm start`\n5. enjoy!\n\n## How to use CLI?\n\n1. install `typeorm` globally: `npm i -g typeorm`\n2. run `typeorm -h` to show list of available commands\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevniel%2Fexample-typeorm-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevniel%2Fexample-typeorm-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevniel%2Fexample-typeorm-testing/lists"}