Skip to content

Commit

Permalink
jquense#2043 add Error toStringTag to custom ValidationError class
Browse files Browse the repository at this point in the history
  • Loading branch information
tedeschia committed Jul 29, 2023
1 parent 5b12965 commit 35085a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ValidationError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ export default class ValidationError implements Error {
if (!disableStack && Error.captureStackTrace)
Error.captureStackTrace(this, ValidationError);
}
[Symbol.toStringTag] = 'Error';
}
13 changes: 12 additions & 1 deletion test/array.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { string, number, object, array, StringSchema, AnySchema } from '../src';
import {
string,
number,
object,
array,
StringSchema,
AnySchema,
ValidationError,
} from '../src';

describe('Array types', () => {
describe('casting', () => {
Expand Down Expand Up @@ -56,6 +64,9 @@ describe('Array types', () => {

let merged = array(number()).concat(array(number().required()));

const ve = new ValidationError('');
// expect(ve.toString()).toBe('[object Error]');
expect(Object.prototype.toString.call(ve)).toBe('[object Error]');
expect((merged.innerType as AnySchema).type).toBe('number');

await expect(merged.validateAt('[0]', undefined)).rejects.toThrowError();
Expand Down

0 comments on commit 35085a8

Please sign in to comment.