mardi 30 juillet 2019

How to test a function inside a default function of a Worker in Jest?

I have a Javascript file, sortWorker.js, of the following format:

export default () => {

    function sortData (data) {
        //some computation here

        return sortedData
    }

    self.addEventListener ("message", e => {
        postMessage(sortData(e.data))
    })
}

I am trying to test the sortData() function in isolation in Jest, but I am struggling to achieve this. Since this is a worker file, I cannot move sortData outside the export default scope. Could someone please help me with this? Thanks!

Aucun commentaire:

Enregistrer un commentaire