jeudi 13 août 2020

How write unit test case for below in jasmine

 public writeValue(item): void {
        this.data = item;
        if (this.salesDivision.length <= 0)
            return

        if(item.length> 0)
        for(let i=0;i<=item.length-1;i++)
        {
            this.salesDivisionTagSet.push(item[i]);
        }
               
        if (Array.isArray(this.data)) {
            const data = this.salesDivision.map(l => ({ isSelected: this.data.includes(l.id), id: l.id, name: l.name }))
            this.selectedList = JSON.stringify(data);
        } else {
            const data = this.salesDivision.map(l => ({ isSelected: this.data === l.id, id: l.id, name: l.name }));
            this.selectedList = JSON.stringify(data);
        }
        this.selectedList = JSON.parse(this.selectedList);
        this.renderer.setProperty(this.elementRef.nativeElement, 'suggestionlist', this.selectedList);
        this.onChange(item);
    }

iam new to angular testing i am not able to write unit test cases for the above because of this coverage is not increasing can somebody help me with this .

I have written following test cases

// it("",()=>{
//  const data =[9,7]
//   if (Array.isArray(data)) {
//     spyOn(component.salesDivision, "map");
//     component.writeValue(9);
//     spyOn(component.salesDivision, "map");
//     expect(component.salesDivisionTagSet.map).toHaveBeenCalled();
   
// } 
// })

Aucun commentaire:

Enregistrer un commentaire