1

我有一个类,其中使用 inversify 的构造函数注入来注入多个对象。

//file Doctor.ts
import { inject } from 'inversify';

export class Doctor {
  private stetho: Stetho;
  private syringe: Syringe;

  constructor(
    @inject(Stetho) stetho: Stetho,
    @inject(Syringe) syringe: Syringe
  ) {
    this.stetho = stetho;
    this.syringe = syringe;
  }

  getName() {
    return "doctor";
  }
}

我正在jest使用以下方式对此进行测试。

//file test.ts
import { Doctor } from './Doctor';

describe("sample test", () => {
  test("test name", () => {
    const doctor = new Doctor();

    expect(doctor.getName()).toBe("doctor");
  });
});

测试运行良好,但new Doctor()抛出 ts lint 错误的行表明Expected two arguments but received 0.

有没有办法在不使用@ts-ignore或使用属性注入的情况下避免这种情况?

4

0 回答 0