fileUtils.test.ts 788 B

1234567891011121314151617181920212223242526272829
  1. import { describe, test, it, expect } from 'vitest'
  2. import FileUtils from '~/services/utils/fileUtils'
  3. import 'blob-polyfill'
  4. describe('newBlob', () => {
  5. test('defaultFiletype', async () => {
  6. const blob = FileUtils.newBlob('test')
  7. expect(await blob.text()).toEqual('test')
  8. expect(await blob.type).toEqual('image/jpeg')
  9. })
  10. test('otherFiletype', async () => {
  11. const blob = FileUtils.newBlob('test', 'image/png')
  12. expect(await blob.text()).toEqual('test')
  13. expect(await blob.type).toEqual('image/png')
  14. })
  15. })
  16. describe('blobToBase64', () => {
  17. test('simple blog', async () => {
  18. const blob = new Blob(['foo' as BlobPart], { type: 'image/jpeg' })
  19. expect(await FileUtils.blobToBase64(blob)).toEqual(
  20. 'data:image/jpeg;base64,Zm9v',
  21. )
  22. })
  23. })