Q:

How to unit test a method that removes duplicates from an array? 

I have the following method that is removing duplicates from an array based on a given property:
   removeDuplicates(myArr, prop) {
        return myArr.filter((object, pos, arr) => {
            return arr.map(obj => obj[prop]).indexOf(object[prop]) === pos;
        });
    }

Now I need to unit test this method, but I don't know how. 
describe('remove duplicates', () => {
  it('should remove duplicated objects from an array based on a property', () => {
   //..
  }
});

How can I properly test methods like this? 

A:

You import your removeDuplicates function. 
You can follow the AAA pattern (Arrange Act Assert).   
describe('removeDuplicates', () => {
  const fixtureComponent = TestBed.createComponent(YourComponent);
  it('should remove objects with same given property', () => {
   // Arrange
   const persons = [
     { id: 1, name: 'John' },
     { id: 2, name: 'Paul' },
     { id: 3, name: 'Ron' },
     { id: 4, name: 'John' },
     { id: 5, name: 'Louis' },
   ];

    // Act
    const distinctPersons = fixtureComponent.removeDuplicates(persons, 'name');

   // Assert
   expect(distinctPersons).toEqual([
     { id: 1, name: 'John' },
     { id: 2, name: 'Paul' },
     { id: 3, name: 'Ron' },
     { id: 5, name: 'Louis' },
   ]);
 }
});

