Angular旁观者,不能使用自定义匹配器

Angular Spectator, cannot use custom matchers

我正在尝试使用 spectator 来测试我的 Angular 组件。 我想使用自定义匹配器之一,但出现错误 Property 'toBeEmpty' does not exist on type 'JestMatchersShape<Matchers<void, Element>, Matchers<Promise<void>, Element>>'.

组件非常简单,这是简单的测试:

  import { FormControl } from '@angular/forms';
  import { Spectator, createComponentFactory } from '@ngneat/spectator';

  import { imports } from '../../shared.module';

  import { InputComponent } from './input.component';

  describe('InputComponent', () => {
    let spectator: Spectator<InputComponent>;
    const createComponent = createComponentFactory({
      component: InputComponent,
      imports: imports,
    });

    describe('label', () => {
      it('should not show when not passed', () => {
        spectator = createComponent({
          props: {
            control: new FormControl(),
          },
        });

        const matLabel = spectator.query('mat-label');

        expect(matLabel).toBeEmpty(); // <-- Error here
      });
    });
  });

我阅读了 spectator 的文档,但没有提及有关导入自定义匹配器的任何内容,还有互联网上的示例,他们没有提及在使用它们之前需要做的任何事情。

我解决了我的问题。

我尝试像这样导入自定义匹配器:

   import { toBeEqual } from '@ngneat/spectator'; 

但我遇到了同样的错误。阅读有关使用 spectator 模拟 Angular 路由器的其他答案 我注意到一个导入:

   import '@ngneat/spectator/jest';

我没有找到有关使用自定义匹配器的说明。

总之,它解决了我的问题。