I recently wrote a primitive pipe used for searching items:
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);
});
}
}
My pipe test file is the default one:
import { SearchPipe } from './search.pipe';
describe('SearchPipe', () => {
it('create an instance', () => {
const pipe = new SearchPipe();
expect(pipe).toBeTruthy();
});
});
When I run my test inside of another component, which uses the search pipe I get the following error:
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
Any clue why this is happening? How to fix this error?