'Testing my function that converts base64 to url

I have my function to convert base 64 to url

function convertB64ToUrl(cameraImage: string): string {
    const byteString = atob(cameraImage)
    const arrayBuffer = new ArrayBuffer(byteString.length)
    const uint8Array = new Uint8Array(arrayBuffer)

    for (let i = 0; i < byteString.length; i++) {
        uint8Array[i] = byteString.charCodeAt(i)
    }
    const blob = new Blob([arrayBuffer], { type: 'image/jpeg' })

    return URL.createObjectURL(blob)
}

Later in my code I used return of this function at src in <img/>. It works fine.

My question is how can I properly test it?

I develop only one small test

test('Util function convertB64ToUrl should convert given string to url', () => {
    const initialData = convertB64ToUrl(btoa('Hello'))
    expect(initialData).toStrictEqual(new Blob(['Hello'], { type: 'image/jpeg' }))
})


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source