imageUtils.test.ts 824 B

123456789101112131415161718192021222324252627
  1. import { describe, test, it, expect } from 'vitest'
  2. import ImageUtils from "~/services/utils/imageUtils";
  3. import 'blob-polyfill';
  4. describe('newBlob', () => {
  5. test('defaultFiletype', async () => {
  6. const blob = ImageUtils.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 = ImageUtils.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 ImageUtils.blobToBase64(blob)).toEqual('data:image/jpeg;base64,Zm9v')
  20. })
  21. })