|
- import * as fc from 'fast-check'
- import dataUriToBlob from './dataUriToBlob'
-
- it('should exist', () => {
- expect(dataUriToBlob).toBeDefined()
- })
-
- it('should be a callable', () => {
- expect(typeof dataUriToBlob).toBe('function')
- })
-
- it('should accept 2 arguments', () => {
- expect(dataUriToBlob).toHaveLength(2)
- })
-
- it('should throw an error for invalid parameters', () => {
- fc.assert(
- fc.property(
- fc.anything().filter(s => typeof s !== 'string'),
- s => {
- expect(() => dataUriToBlob(s as string)).toThrow(TypeError)
- }
- )
- )
- })
-
- it('should return a Blob for valid parameters', () => {
- fc.assert(
- fc.property(fc.base64String(), binaryBase64 => {
- const dataUri = `data:application/octet-stream;base64,${binaryBase64}`
- expect(dataUriToBlob(dataUri).constructor.name).toBe('Blob')
- })
- )
- })
-
- it('should return a File for named Blobs', () => {
- fc.assert(
- fc.property(
- fc.tuple(
- fc.base64String(),
- fc.string().filter(s => /^[a-zA-Z0-9._-]+$/.test(s))
- ),
- ([binaryBase64, fileName]) => {
- const dataUri = `data:application/octet-stream;base64,${binaryBase64}`
- expect(dataUriToBlob(dataUri, fileName).constructor.name).toBe('File')
- }
- )
- )
- })
|