首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular Spectator,不能使用自定义匹配器

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

Stack Overflow用户
提问于 2020-11-11 17:55:10
回答 1查看 134关注 0票数 0

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

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

代码语言:javascript
复制
  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
      });
    });
  });

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-11 19:02:20

我解决了我的问题。

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

代码语言:javascript
复制
   import { toBeEqual } from '@ngneat/spectator'; 

但我也收到了同样的错误。在阅读关于用spectator模拟Angular路由器的其他答案时,我注意到了一个要点:

代码语言:javascript
复制
   import '@ngneat/spectator/jest';

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

不管怎样,它解决了我的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64784180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档