-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
50ec701
commit 34cc499
Showing
7 changed files
with
29 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import { describe, it, expect, beforeEach } from 'vitest'; | ||
import { toDataURL, toText, toArrayBuffer } from '../src/file'; | ||
import { describe, it, expect, beforeEach } from 'vitest' | ||
import { toDataURL, toText, toArrayBuffer } from '../src' | ||
|
||
describe('file', () => { | ||
let file: File; | ||
let file: File | ||
|
||
beforeEach(() => { | ||
const blob = new Blob(['Hello, World!'], { type: 'text/plain' }); | ||
file = new File([blob], 'hello.txt', { type: 'text/plain' }); | ||
}); | ||
const blob = new Blob(['Hello, World!'], { type: 'text/plain' }) | ||
file = new File([blob], 'hello.txt', { type: 'text/plain' }) | ||
}) | ||
|
||
describe('toDataURL', () => { | ||
it('should convert file to data URL', async () => { | ||
const dataURL = await toDataURL(file); | ||
expect(dataURL).toMatch(/^data:text\/plain;base64,/); | ||
}); | ||
}); | ||
const dataURL = await toDataURL(file) | ||
expect(dataURL).toMatch(/^data:text\/plain;base64,/) | ||
}) | ||
}) | ||
|
||
describe('toText', () => { | ||
it('should read file as text', async () => { | ||
const text = await toText(file); | ||
expect(text).toBe('Hello, World!'); | ||
}); | ||
}); | ||
const text = await toText(file) | ||
expect(text).toBe('Hello, World!') | ||
}) | ||
}) | ||
|
||
describe('toArrayBuffer', () => { | ||
it('should read file as array buffer', async () => { | ||
const arrayBuffer = await toArrayBuffer(file); | ||
expect(arrayBuffer).toBeInstanceOf(ArrayBuffer); | ||
const arrayBuffer = await toArrayBuffer(file) | ||
expect(arrayBuffer).toBeInstanceOf(ArrayBuffer) | ||
|
||
const uint8Array = new Uint8Array(arrayBuffer); | ||
const text = new TextDecoder().decode(uint8Array); | ||
expect(text).toBe('Hello, World!'); | ||
}); | ||
}); | ||
}); | ||
const uint8Array = new Uint8Array(arrayBuffer) | ||
const text = new TextDecoder().decode(uint8Array) | ||
expect(text).toBe('Hello, World!') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters