我在解决问题的过程中浪费了几个小时。这是答案。例如,我们需要注入ElementRef和NgControl:
import { inject } from '@angular/core/testing';
import { ElementRef } from '@angular/core';
import { NgControl } from '@angular/forms'
import { MyDirective } from './my.directive';
describe('MyDirective', () => {
it('should create an instance', inject([ElementRef, NgControl], (elementRef: ElementRef, ngControl: NgControl) => {
const directive = new MyDirective(elementRef, ngControl);
expect(directive).toBeTruthy();
}));
});
});