我正在尝试使用 Nestjs/Typeorm 和事务来在每个 e2e 测试之前/之后启动和回滚数据库状态。
我在下面包含了一个代码片段尝试。我试图重写 EntityManager 提供程序,以便使用 QueryRunner 实例对其进行初始化,以便我可以在每次测试之前/之后启动和回滚事务。但是,我似乎无法获取存储库(请参阅下面代码片段中的 beforeEach 方法中的注释)来使用我重写的 EntityManager 实例,以启用成功的事务使用......我认为这就是为什么事务在每次之后都不会回滚的原因测试完成了??
let app: INestApplication;
let testModule: TestingModule;
afterEach(async () => {
const em: EntityManager = testModule.get(getEntityManagerToken('default'));
await em.queryRunner.rollbackTransaction();
});
beforeEach(async () => {
const con: Connection = testModule.get(Connection);
const em: EntityManager = testModule.get(getEntityManagerToken('default'));
const repo: CourseRepository = testModule.get(CourseRepository);
const result: boolean = repo.isEntityManagerMine(em); // false => the repo is not using the default entity manager
const conResult: boolean = repo.isConnectionMine(em.connection); // true => the repo is using …Run Code Online (Sandbox Code Playgroud) 我在Angular Reactive Forms应用程序中使用PrimeNG Calendar控件。在我的应用程序中,我在Primefaces对话框中有一个带有日历控件的表单。
当在日历控件中键入无效的日期值时,在关闭对话框时,我会以编程方式将控件的值更新为预定义的回滚日期值,以便再次显示该窗体时,该窗体处于有效状态。
但是,我发现以编程方式更新日历控件的值并不能始终以新值更新UI。
我正在使用FormGroup,并尝试过setValue和patchValue。我也尝试过在日历控件上显式使用setValue和patchValue以及formGroup的重置方法。仍然出现问题。
只是想知道是否有人可以建议我在代码中哪里出错了?
我在http://plnkr.co/edit/xc4ygZ?p=info创建了一个插件,以说明一个例子。角度组件和模板的代码包含在下面。
import {
Component
} from '@angular/core';
import {
FormBuilder
} from '@angular/forms';
import {
FormGroup
} from '@angular/forms';
import {
OnInit
} from '@angular/core';
import {
Validators
} from '@angular/forms';
@Component({
selector: 'my-app',
templateUrl: 'app/app.template.html'
})
export class AppComponent {
birthDate: Date;
form: FormGroup;
formErrors = {
'setdate': '',
};
validationMessages = {
'setdate': {
'required': 'Set date is required.',
'invalidDate': 'Invalid Date.'
},
};
constructor(private fb: FormBuilder) { …Run Code Online (Sandbox Code Playgroud)我正在尝试模拟一个封装在使用 NestJS 创建的服务类中的winston.Logger实例。我在下面包含了我的代码。
我无法从服务类中触发模拟记录器实例。谁能解释我哪里出错了?
import * as winston from 'winston';
import { loggerOptions } from '../logger/logger.config';
import { LoggingService } from '../logger/logger.service';
const logger: winston.Logger = winston.createLogger(loggerOptions);
// trying to mock createLogger to return a specific logger instance
const winstonMock = jest.mock('winston', () => (
{
format: {
colorize: jest.fn(),
combine: jest.fn(),
label: jest.fn(),
timestamp: jest.fn(),
printf: jest.fn()
},
createLogger: jest.fn().mockReturnValue(logger),
transports: {
Console: jest.fn()
}
})
);
describe("-- Logging Service --", () => {
let loggerMock: winston.Logger; …Run Code Online (Sandbox Code Playgroud)