ray-template/__test__/basic/arrayBufferToBase64Image.spec.ts
2024-03-23 11:25:28 +08:00

19 lines
608 B
TypeScript

import { arrayBufferToBase64Image } from '../../src/utils/basic'
describe('arrayBufferToBase64Image', () => {
const arrayBuffer = new ArrayBuffer(8)
const base64ImagePrefix = 'data:image/png;base64,'
it('should convert array buffer to base64 image', () => {
const base64Image = arrayBufferToBase64Image(arrayBuffer)
expect(base64Image).toBe(`${base64ImagePrefix}AAAAAAAAAAA=`)
})
it('should convert array buffer to base64 image with prefix', () => {
const base64Image = arrayBufferToBase64Image(arrayBuffer)
expect(base64Image.startsWith(base64ImagePrefix)).toBe(true)
})
})