From 30f4b45785fdc5e4ae32909d2a7367d6d7a8a182 Mon Sep 17 00:00:00 2001 From: Robin De Schepper Date: Tue, 24 Jan 2023 17:59:12 +0100 Subject: [PATCH] Replaced deprecated `Connection` API in tests (#451) --- src/paginate.spec.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/paginate.spec.ts b/src/paginate.spec.ts index a469407..b993cb8 100644 --- a/src/paginate.spec.ts +++ b/src/paginate.spec.ts @@ -1,4 +1,4 @@ -import { createConnection, Repository, In, Connection } from 'typeorm' +import { Repository, In, DataSource } from 'typeorm' import { Paginated, paginate, @@ -17,7 +17,7 @@ import { CatHomeEntity } from './__tests__/cat-home.entity' import { clone } from 'lodash' describe('paginate', () => { - let connection: Connection + let dataSource: DataSource let catRepo: Repository let catToyRepo: Repository let catHomeRepo: Repository @@ -26,16 +26,18 @@ describe('paginate', () => { let catHomes: CatHomeEntity[] beforeAll(async () => { - connection = await createConnection({ + dataSource = new DataSource({ type: 'sqlite', database: ':memory:', synchronize: true, logging: false, entities: [CatEntity, CatToyEntity, CatHomeEntity], }) - catRepo = connection.getRepository(CatEntity) - catToyRepo = connection.getRepository(CatToyEntity) - catHomeRepo = connection.getRepository(CatHomeEntity) + await dataSource.initialize() + catRepo = dataSource.getRepository(CatEntity) + catToyRepo = dataSource.getRepository(CatToyEntity) + catHomeRepo = dataSource.getRepository(CatHomeEntity) + cats = await catRepo.save([ catRepo.create({ name: 'Milo', color: 'brown', age: 6, size: { height: 25, width: 10, length: 40 } }), catRepo.create({ name: 'Garfield', color: 'ginger', age: 5, size: { height: 30, width: 15, length: 45 } }), @@ -98,7 +100,7 @@ describe('paginate', () => { path: '', } - const queryBuilder = await connection + const queryBuilder = await dataSource .createQueryBuilder() .select('cats') .from(CatEntity, 'cats')