I have a function where it just computes the data and render into HTML, I want to write a test case to a filter function
@Input() tableData:any
private populateTableData(){
const gridData : any[] = this.tableData; // this.tableData is @Input variable
if(gridData){
const tableElements = gridData.filter(
(v) => v.identifier == 'tableData'
);
}
}
Json(object) data which comes as an Input (tableData) for the function
[{
"identifier": "tableData",
"data": [
{
"displayName":"name",
"displayOrder": 1,
"bindKey":"name"
},
{
"displayName":"email",
"displayOrder": 2,
"bindKey":"email"
}
]
}]
as the populateTableData function is private I Implemented the below test case
beforeEach(() =>{
fixture = TestBed.createComponent(DynamicTableComponent);
component = fixture.componentInstance;
fixture.detectChanges();
})
describe('populateTableData', ()=>{
it('should filter the tableData with the identifier tableData', () => {
let gridData = "identifier": "tableData",
"data": [
{
"displayName":"name",
"displayOrder": 1,
"bindKey":"name"
},
{
"displayName":"email",
"displayOrder": 2,
"bindKey":"email"
}
]
component['populateTableData'](); // called the private function
// how to check the filter operations performed in the function
})
})
how can I write the test cases for the filter function defined in the populateTableData function