mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-12 09:01:32 -04:00
refactor(base64-to-file): clean validation to convert base64 to file
This commit is contained in:
parent
5f03619ab4
commit
750a76b00f
4 changed files with 113 additions and 22 deletions
29
src/composable/validation.test.ts
Normal file
29
src/composable/validation.test.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isFalsyOrHasThrown } from './validation';
|
||||
|
||||
describe('useValidation', () => {
|
||||
describe('isFalsyOrHasThrown', () => {
|
||||
it('should return true if the callback return nil, false or throw', () => {
|
||||
expect(isFalsyOrHasThrown(() => false)).toBe(true);
|
||||
expect(isFalsyOrHasThrown(() => null)).toBe(true);
|
||||
expect(isFalsyOrHasThrown(() => undefined)).toBe(true);
|
||||
expect(isFalsyOrHasThrown(() => {})).toBe(true);
|
||||
expect(
|
||||
isFalsyOrHasThrown(() => {
|
||||
throw new Error();
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for any truthy values and empty string and 0 values', () => {
|
||||
expect(isFalsyOrHasThrown(() => true)).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => 'string')).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => 1)).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => 0)).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => '')).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => [])).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => ({}))).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue