gpt4 book ai didi

angular - Jasmine 测试 TypeORM - 错误 : DriverPackageNotInstalledError: SQLite package has not been found installed

转载 作者:行者123 更新时间:2023-12-05 05:09:51 32 4
gpt4 key购买 nike

我正在尝试对使用 TypeORM 连接更新 sqlite 数据库的服务进行单元测试。

似乎没有固定的方法来对 TypeORM 进行单元测试,所以我正在尝试找到任何可行的方法。根据以下内容,我决定尝试使用内存数据库进行测试:

https://github.com/typeorm/typeorm/issues/1267#issuecomment-483775861

那里的代码使用 Jest,所以我正在尝试转换为 Jasmine,这是我的测试环境。

作为原理证明,如果我在 database-test.spec.ts

中执行以下操作
import { createConnection, Entity, getRepository } from "typeorm";
import { PrimaryGeneratedColumn, Column } from "typeorm";
import { fakeAsync, async } from "@angular/core/testing";

@Entity()
export class MyEntity {
@PrimaryGeneratedColumn()
id?: number;

@Column()
name?: string;
}

describe("Database test", () => {
it("store Joe and fetch it", fakeAsync(() => {
createConnection({
name: "testing",
type: "sqlite",
database: ":memory:",
dropSchema: true,
entities: [MyEntity],
synchronize: true,
logging: false,
}).then(conn => {
conn.getRepository(MyEntity).insert({
name: "Joe",
});
const joe = getRepository(MyEntity).find({
where: {
id: 1,
},
});

expect(joe[0].name).toBe("Joe");
conn.close();
});
}));
});

无论我做什么我都会出错

Failed: Uncaught (in promise): DriverPackageNotInstalledError: SQLite package has not been found installed. Try to install it: npm install sqlite3 --save
DriverPackageNotInstalledError: SQLite package has not been found installed. Try to install it: npm install sqlite3 --save
at new DriverPackageNotInstalledError (http://localhost:9876/_karma_webpack_/webpack:/node_modules/typeorm/browser/error/DriverPackageNotInstalledError.js:8:1)
at SqliteDriver.loadDependencies (http://localhost:9876/_karma_webpack_/webpack:/node_modules/typeorm/browser/driver/sqlite/SqliteDriver.js:118:1)
at new SqliteDriver (http://localhost:9876/_karma_webpack_/webpack:/node_modules/typeorm/browser/driver/sqlite/SqliteDriver.js:24:1)
at DriverFactory.create (http://localhost:9876/_karma_webpack_/webpack:/node_modules/typeorm/browser/driver/DriverFactory.js:35:1)
at new Connection (http://localhost:9876/_karma_webpack_/webpack:/node_modules/typeorm/browser/connection/Connection.js:50:40)
at ConnectionManager.create (http://localhost:9876/_karma_webpack_/webpack:/node_modules/typeorm/browser/connection/ConnectionManager.js:54:1)
at Module.<anonymous> (http://localhost:9876/_karma_webpack_/webpack:/node_modules/typeorm/browser/index.js:171:1)
at step (http://localhost:9876/_karma_webpack_/webpack:/node_modules/tslib/tslib.es6.js:99:1)
at Object.next (http://localhost:9876/_karma_webpack_/webpack:/node_modules/tslib/tslib.es6.js:80:45)
at http://localhost:9876/_karma_webpack_/webpack:/node_modules/tslib/tslib.es6.js:73:1

SQLite 已安装并可在测试之外运行。为什么在测试期间会出现此错误?

其他信息:我正在使用入门工具包:https://github.com/CubikNeRubik/angular-electron-typeorm-starter

最佳答案

请安装 sqlite3

如果 typeorm 选项指定为 database:':memory',则使用 sqlite3 库创建并在运行实例中使用 sqlite .

如果您想使用外部 sqlite3,请查看此页面。

https://github.com/mapbox/node-sqlite3#source-install

关于angular - Jasmine 测试 TypeORM - 错误 : DriverPackageNotInstalledError: SQLite package has not been found installed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57159356/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com