小编dcs*_*spp的帖子

Nestjs / Typeorm 在每次测试后使用事务回滚数据库状态

我正在尝试使用 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)

nestjs typeform

6
推荐指数
1
解决办法
3102
查看次数

当日历控件处于无效状态时,PrimeNG日历控件的“活动表单”更新值看不到更新日历UI

我在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)

primeng angular angular4-forms

5
推荐指数
1
解决办法
2139
查看次数

如何使用Jest模拟封装在服务类中的winston logger实例

我正在尝试模拟一个封装在使用 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)

winston typescript jestjs nestjs

4
推荐指数
2
解决办法
7441
查看次数