小编Smn*_*Hgr的帖子

出现错误消息 TypeError: this.subQuery is not a function

如果我用 jest 运行测试,我总是收到错误消息TypeError: this.subQuery is not a function,并在 testModelDb.test.ts 文件中的标记行上引用

测试/jest.setup.ts

import 'reflect-metadata';
import dotenv from 'dotenv';
dotenv.config({ path: './.env.test' });
Run Code Online (Sandbox Code Playgroud)

.env.test

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
Run Code Online (Sandbox Code Playgroud)

src/models/test.model.ts

@Entity()
export default class TestModel {
    @PrimaryGeneratedColumn()
    id!: number;

    @Column()
    name!: string;

    @OneToMany(() => OtherModel, (other) => other.testModel)
    otherModels!: OtherModel[];
}
Run Code Online (Sandbox Code Playgroud)

测试/testModelDb.test.ts

describe('Integrationtests', () => {
    let connection: Connection;

    beforeAll(async () => { connection = await createConnection(); });

    afterAll(() => connection?.close());

    beforeEach(async () => { await connection.synchronize(true); }); …
Run Code Online (Sandbox Code Playgroud)

typescript jestjs typeorm

7
推荐指数
1
解决办法
3026
查看次数

标签 统计

jestjs ×1

typeorm ×1

typescript ×1