Useful methods for file-related functions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

  1. import * as fc from 'fast-check'
  2. import dataUriToBlob from './dataUriToBlob'
  3. it('should exist', () => {
  4. expect(dataUriToBlob).toBeDefined()
  5. })
  6. it('should be a callable', () => {
  7. expect(typeof dataUriToBlob).toBe('function')
  8. })
  9. it('should accept 2 arguments', () => {
  10. expect(dataUriToBlob).toHaveLength(2)
  11. })
  12. it('should throw an error for invalid parameters', () => {
  13. fc.assert(
  14. fc.property(
  15. fc.anything().filter(s => typeof s !== 'string'),
  16. s => {
  17. expect(() => dataUriToBlob(s as string)).toThrow(TypeError)
  18. }
  19. )
  20. )
  21. })
  22. it('should return a Blob for valid parameters', () => {
  23. fc.assert(
  24. fc.property(fc.base64String(), binaryBase64 => {
  25. const dataUri = `data:application/octet-stream;base64,${binaryBase64}`
  26. expect(dataUriToBlob(dataUri).constructor.name).toBe('Blob')
  27. })
  28. )
  29. })
  30. it('should return a File for named Blobs', () => {
  31. fc.assert(
  32. fc.property(
  33. fc.tuple(
  34. fc.base64String(),
  35. fc.string().filter(s => /^[a-zA-Z0-9._-]+$/.test(s))
  36. ),
  37. ([binaryBase64, fileName]) => {
  38. const dataUri = `data:application/octet-stream;base64,${binaryBase64}`
  39. expect(dataUriToBlob(dataUri, fileName).constructor.name).toBe('File')
  40. }
  41. )
  42. )
  43. })