Flag(a) { let element=this.selected.filter(item => item.a=== a) return element.length > 1 ? true : false; }
Not sure how to write a unit test case for the above function. Can you please help
A test case consists always of 3 steps:
In your case this means:
this.selected
This should be pretty easy:
it('should run #Flag(a) method', () => { component.selected = [{ someKey1: 'someValue1' }, { someKey2: 'someValue2' }]; const val = 'someValue1'; spyOn(component, 'Flag').and.callThrough(); component.Flag(val); expect(component.Flag).toHaveBeenCalled(); })