Created
February 23, 2021 21:11
-
-
Save ErikGMatos/c21de0e47e12ec3a9550dcaf09551859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//função que quero testar | |
export const fileToBase64 = file => | |
new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(file); | |
reader.onload = () => { | |
resolve(reader.result); | |
}; | |
reader.onerror = error => { | |
reject(error); | |
}; | |
}); | |
//meu teste | |
describe('Teste para a função fileToBase64', () => { | |
// aqui passa no onload | |
it('Deve retornar a string do arquivo em base64', async () => { | |
const mFile = new File(['go'], 'go.pdf'); | |
const response = await fileToBase64(mFile); | |
expect(response).toBe('data:;base64,Z28='); | |
}); | |
//aqui queria simular um erro no onerror, porem nao consigo | |
it('Deve retornar erro', async () => { | |
const mFile = 1; | |
const response = await fileToBase64(mFile); | |
expect(response).toThrow(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment