Skip to content

fix(renderer): allow negative numbers in dataType #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ describe('New validators', () => {
expect(dataTypeValidator('float')()(123.232)).toBeUndefined();
});

it('should return negative number and pass', () => {
expect(dataTypeValidator('number')()(-123.232)).toBeUndefined();
});

it('should return negative integer and pass', () => {
expect(dataTypeValidator('integer')()(-123)).toBeUndefined();
});

it('should return negative float and pass', () => {
expect(dataTypeValidator('float')()(-123.123)).toBeUndefined();
});

it('should return float and pass 2', () => {
expect(dataTypeValidator('float')()(123)).toBeUndefined();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,20 @@ export const dataTypeValidator = (type) =>
string: (options) => stringValidator({ message: 'Field value has to be string', ...options }),
integer: (options) =>
pattern({
pattern: /^\d*$/,
pattern: /^-?\d*$/,
message: 'Value must be integer',
...options,
}),
boolean: (options) => booleanValidator({ message: 'Field value has to be boolean', ...options }),
number: (options) =>
pattern({
pattern: /^\d*[.]{0,1}\d*$/,
pattern: /^-?\d*[.]{0,1}\d*$/,
message: 'Values must be number',
...options,
}),
float: (options) =>
pattern({
pattern: /^\d*[.]{0,1}\d*$/,
pattern: /^-?\d*[.]{0,1}\d*$/,
message: 'Values must be number',
...options,
}),
Expand Down