可能是因为缺少相关的导入。尝试在相应的.spec.ts文件中导入“KeyValuePipe”并添加到TestBed.configureTestingModle()中的“declarations”数组中。示例如下:
import { KeyValuePipe } from '@angular/common';
describe('MyComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ MyComponent, KeyValuePipe ]
    })
    .compileComponents();
  })));
  it('should create the component', () => {
    const fixture = TestBed.createComponent(MyComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  });
});