mardi 2 mai 2017

Testing an Array Filter callback inside a function

I have a function

handleCSV () {
  this.storeData$.take(1).subscribe(s => {
    const data = s.data
    const fields = ['reference', 'description', 'val1', 'val2', 'difference']
    const fieldNames = ['Reference', 'Description', 'Value 1', 'Value 2', 'Difference']
    const exportData = data.filter(dataset => dataset.visible)

    const csv = json2csv({ data: exportData, fields: fields, fieldNames: fieldNames })
    const csvEnc = encodeURIComponent(csv)
    const href = `data:application/octet-stream,${csvEnc}`

    this.csvDownloadLink.nativeElement.setAttribute('href', href)
    this.csvDownloadLink.nativeElement.click()

    this.csvDownloadLink.nativeElement.setAttribute('href', '')
  })
}

I very almost have 100% coverage of this function, the only thing missing is the data.filter callback

enter image description here

Does anyone know how to test this? The testing library used is Jasmine, the app at large is built with Angular.

Aucun commentaire:

Enregistrer un commentaire