0

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 }) ].
Johansrk
  • 4,809
  • 3
  • 32
  • 32

1 Answers1

1

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 ===.

Korfoo
  • 489
  • 2
  • 9