Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我刚才安装的管道在使用Karma进行测试时找不到_Javascript_Angular_Typescript_Unit Testing_Karma Jasmine - Fatal编程技术网

Javascript 我刚才安装的管道在使用Karma进行测试时找不到

Javascript 我刚才安装的管道在使用Karma进行测试时找不到,javascript,angular,typescript,unit-testing,karma-jasmine,Javascript,Angular,Typescript,Unit Testing,Karma Jasmine,我最近编写了一个用于搜索项目的基本管道: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'search' }) export class SearchPipe implements PipeTransform { transform(value: any, args?: any): any { if (!value) {return null; } if (!args) {ret

我最近编写了一个用于搜索项目的基本管道:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'search'
})
export class SearchPipe implements PipeTransform {

  transform(value: any, args?: any): any {

    if (!value) {return null; }
    if (!args) {return value; }

    args = args.toLowerCase();

    return value.filter((item) => {
        return JSON.stringify(item).toLowerCase().includes(args);
    });
}

}
我的管道测试文件是默认文件:

import { SearchPipe } from './search.pipe';

describe('SearchPipe', () => {
  it('create an instance', () => {
    const pipe = new SearchPipe();
    expect(pipe).toBeTruthy();
  });
});
当我在另一个使用搜索管道的组件内部运行测试时,我得到以下错误:

Failed: Template parse errors:
The pipe 'search' could not be found ("target.value)">
      <!-- maybe add | async pipe -->
    <option class="fetchedUser" *ngFor="let [ERROR ->]user of users | search: query" value="{{user.firstname}}">
        {{user?.lastname}}, {{user?.first"): ng:///DynamicTestModule/UsersComponent.html@13:44
失败:模板分析错误:
找不到管道“搜索”(“target.value)”>
{{user?.lastname},{{user?.first”):ng:///DynamicTestModule/UsersComponent。html@13:44

出现这种情况的任何线索?如何修复此错误?

这是否回答了您的问题?@nopassport1如果我尝试按照答案操作,我会得到错误
错误TS2339:类型“typeof SearchPipe”上不存在属性“forRoot”。
:/@nopassport1如果我添加它时没有.forRoot()我收到以下错误:
失败:模块“DynamicTestModule”导入了意外的管道“SearchPipe”。请添加@NgModule注释。
在技术上不是错误的答案,在我的模块中导入了。ts我的管道作为声明。