我希望尽可能多地对我的应用程序进行单元和端到端测试,我的目标是覆盖率达到 101%。我的设置现在的问题是,typeorm 的 @Column 装饰器使用箭头函数来设置默认值,例如数据库更新的当前时间戳。这个箭头函数没有被玩笑测试覆盖。消息是:statement not covered
我运行代码覆盖率:jest --coverage
。
我的版本:
"jest": "^24.9.0",
"typeorm": "^0.2.20"
package.json 中的 Jest 配置:
{
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../build/coverage",
"testEnvironment": "node",
"coverageThreshold": {
"global": {
"branches": 80,
"functions": 80,
"lines": 80,
"statements": -10
}
}
},
}
我的实体看起来像这样:
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Role {
@PrimaryGeneratedColumn()
id: number;
@Column()
tenantId: number;
@Column({ type: 'timestamp', update: false, default: () => 'CURRENT_TIMESTAMP()' })
createdAt: Date;
@Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP()', onUpdate: 'CURRENT_TIMESTAMP()' })
updatedAt: Date;
}
该实体的覆盖范围: