refactor(validation): simplified validation management with helpers
This commit is contained in:
5 files changed
+35
-39
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isNotThrowing } from './boolean';
|
||||
|
||||
describe('boolean utils', () => {
|
||||
describe('isNotThrowing', () => {
|
||||
it('should return if the call throws or false otherwise', () => {
|
||||
expect(isNotThrowing(() => {})).to.eql(true);
|
||||
expect(
|
||||
isNotThrowing(() => {
|
||||
throw new Error();
|
||||
}),
|
||||
).to.eql(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
export { isNotThrowing };
|
||||
|
||||
function isNotThrowing(cb: () => unknown): boolean {
|
||||
try {
|
||||
cb();
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user