Angular 棱角分明的旁观者,不能使用自定义匹配器
我试着用它来测试我的角度分量。 我想使用一个自定义匹配器,但我得到的错误是类型“JestMatchersShape”上不存在属性“toBeEmpty” 组件非常简单,这是一个简单的测试:Angular 棱角分明的旁观者,不能使用自定义匹配器,angular,unit-testing,angular-spectator,spectator,Angular,Unit Testing,Angular Spectator,Spectator,我试着用它来测试我的角度分量。 我想使用一个自定义匹配器,但我得到的错误是类型“JestMatchersShape”上不存在属性“toBeEmpty” 组件非常简单,这是一个简单的测试: import { FormControl } from '@angular/forms'; import { Spectator, createComponentFactory } from '@ngneat/spectator'; import { imports } from '../../s
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
});
});
});
从'@angular/forms'导入{FormControl};
从'@ngneat/consignator'导入{consignator,createComponentFactory};
从“../../shared.module”导入{imports};
从“./input.component”导入{InputComponent};
描述('InputComponent',()=>{
让观众:观众;
const createComponent=createComponentFactory({
组件:输入组件,
进口:进口,,
});
描述('标签',()=>{
它('未通过时不应显示',()=>{
旁观者=创建组件({
道具:{
控件:新建FormControl(),
},
});
const matLabel=旁观者查询('mat-label');
expect(matLabel).toBeEmpty();//我解决了我的问题
我尝试像这样导入自定义匹配器:
import { toBeEqual } from '@ngneat/spectator';
但是我也犯了同样的错误。阅读关于用<代码>旁观者代码>
我注意到一个要点:
import '@ngneat/spectator/jest';
我没有找到使用自定义匹配器的相关说明
不管怎样,它解决了我的问题