aboutsummaryrefslogtreecommitdiff
path: root/src/composable/validation.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/composable/validation.test.ts')
-rw-r--r--src/composable/validation.test.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/composable/validation.test.ts b/src/composable/validation.test.ts
new file mode 100644
index 0000000..0bcb51f
--- /dev/null
+++ b/src/composable/validation.test.ts
@@ -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);
+ });
+ });
+});