Angular Spectator,不能使用自定义匹配器

问题描述

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

我阅读了观众的文档,没有提到导入自定义匹配器的任何内容,也没有在互联网上的示例中提及在使用它们之前要做的任何事情。

解决方法

我解决了我的问题。

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

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

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

   import '@ngneat/spectator/jest';

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

无论如何,它解决了我的问题。