Reputation: 5250
I have a pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filterArrayPipe'
})
export class FilterArrayPipe implements PipeTransform {
transform(value: any, config: any, q: string) {
if (config && q) {
return value.filter(result => {
return config.some(type => result[type].toString().toLowerCase().indexOf(q) > -1);
});
} else {
return value;
}
}
}
and now I want to make a unit test
import { FilterArrayPipe } from './filter-array.pipe';
describe('Pipe: FilterArray Pipe', () => {
it('providing search value should return true', () => {
const pipe = new FilterArrayPipe();
expect(pipe.transform([{id: 123}, {id: 456}], ['id'], '456'))
.toBe([{id: 456}]);
});
});
But I get the follwowing error
Expected [ Object({ id: 456 }) ] to be [ Object({ id: 456 }) ].
Upvotes: 0
Views: 817
Reputation: 611
You should be using toEqual
to do the comparison.
expect(pipe.transform([{id: 123}, {id: 456}], ['id'], '456'))
.toEqual([{id: 456}]);
See toBe vs toEqual for a more detailed answer. It is the same difference as with == and ===.
Upvotes: 1