Whenever I execute the tests using jest, I consistently encounter the error message
TypeError: this.subQuery is not a function
pointing to a specific line in the testModelDb.test.ts file.
In the tests/jest.setup.ts file:
import 'reflect-metadata';
import dotenv from 'dotenv';
dotenv.config({ path: './.env.test' });
The contents of .env.test are as follows:
TYPEORM_CONNECTION=sqlite
TYPEORM_DATABASE=:memory:
TYPEORM_SYNCHRONIZE=true
TYPEORM_LOGGING=false
TYPEORM_ENTITIES=dist/models/**/*.js,modules/**/entity/*.ts
TYPEORM_MIGRATIONS=dist/services/db/seeding.js
TYPEORM_MIGRATIONS_RUN=true
Defined in src/models/test.model.ts:
@Entity()
export default class TestModel {
@PrimaryGeneratedColumn()
id!: number;
@Column()
name!: string;
@OneToMany(() => OtherModel, (other) => other.testModel)
otherModels!: OtherModel[];
}
And finally, in the tests/testModelDb.test.ts file:
describe('Integrationtests', () => {
let connection: Connection;
beforeAll(async () => { connection = await createConnection(); });
afterAll(() => connection?.close());
beforeEach(async () => { await connection.synchronize(true); });
describe(`functions`, () => {
describe(`#function1()`, () => {
test('Test 1', async () => {
await connection
.createQueryBuilder()
.insert()
.into(TestModel) // <- here
.values([ {name: 'Test item 1'} ])
.execute();
expect(true).toBe(true);
});
});
});
});