我正在尝试使用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
});
});
});我看了观众的文档,没有说任何关于导入自定义匹配器的内容,也没有提到互联网上的示例在使用它们之前没有提到要做的任何事情。
发布于 2020-11-11 19:02:20
我解决了我的问题。
我尝试像这样导入自定义匹配器:
import { toBeEqual } from '@ngneat/spectator'; 但我也收到了同样的错误。在阅读关于用spectator模拟Angular路由器的其他答案时,我注意到了一个要点:
import '@ngneat/spectator/jest';我没有找到关于它的使用自定义匹配器的说明。
不管怎样,它解决了我的问题。
https://stackoverflow.com/questions/64784180
复制相似问题