Skip to content

Commit

Permalink
Merge branch 'master' of github.com:deepkit/deepkit-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Jul 27, 2022
2 parents 8660099 + 0e62b1d commit e0ff6b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/type/src/reflection/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ export function isSameType(a: Type, b: Type, stack: StackEntry[] = []): boolean
if (a.kind === ReflectionKind.function || a.kind === ReflectionKind.method || a.kind === ReflectionKind.methodSignature) {
if (b.kind !== ReflectionKind.function && b.kind !== ReflectionKind.method && b.kind !== ReflectionKind.methodSignature) return false;
if (a.parameters.length !== b.parameters.length) return false;
if (a.kind === ReflectionKind.function && b.kind === ReflectionKind.function && a.function !== b.function) return false;

for (let i = 0; i < a.parameters.length; i++) {
if (!isSameType(a.parameters[i], b.parameters[i], stack)) return false;
Expand Down
16 changes: 15 additions & 1 deletion packages/type/tests/validation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from '@jest/globals';
import { expect, test, jest } from '@jest/globals';
import { Email, MaxLength, MinLength, Positive, Validate, validate, validates, ValidatorError } from '../src/validator';
import { assert, is } from '../src/typeguard';
import { AutoIncrement, Excluded, Group, integer, PrimaryKey, Type, Unique } from '../src/reflection/type';
Expand Down Expand Up @@ -69,6 +69,20 @@ test('custom validator with arguments', () => {
expect(() => is<InvalidValidatorOption>('aah')).toThrow(`Invalid option value given to validator function startsWith, expected letter: string`);
});

test('multiple custom validators with identical signatures', () => {
const validator1: (value: any) => void = jest.fn();
const validator2: (value: any) => void = jest.fn();

type MyType = {
a: string & Validate<typeof validator1>;
b: string & Validate<typeof validator2>;
}

expect(is<MyType>({ a: 'a', b: 'b' })).toEqual(true);
expect(validator1).toHaveBeenCalledTimes(1);
expect(validator2).toHaveBeenCalledTimes(1);
});

test('decorator validator', () => {
function minLength(length: number) {
return (value: any): ValidatorError | void => {
Expand Down

0 comments on commit e0ff6b5

Please sign in to comment.