-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { decimal as baseDecimal, helpers } from '@vuelidate/validators' | ||
|
||
export function decimal(msg?: string) { | ||
return helpers.withMessage( | ||
() => msg ?? 'The value must be valid decimal numbers.', | ||
baseDecimal | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { decimal } from 'sefirot/validation/rules' | ||
|
||
describe('validation/rules/decimal', () => { | ||
test('it validates whether the value is decimal', () => { | ||
const rule = decimal() | ||
expect(rule.$validator(0, null, null)).toBe(true) | ||
expect(rule.$validator(1, null, null)).toBe(true) | ||
expect(rule.$validator(-1, null, null)).toBe(true) | ||
expect(rule.$validator(1.1, null, null)).toBe(true) | ||
expect(rule.$validator(-1.1, null, null)).toBe(true) | ||
expect(rule.$validator('1.00', null, null)).toBe(true) | ||
expect(rule.$validator('-1.00', null, null)).toBe(true) | ||
expect(rule.$validator('abc', null, null)).toBe(false) | ||
expect(rule.$validator(true, null, null)).toBe(false) | ||
}) | ||
|
||
test('it can set custome error message', () => { | ||
const rule = decimal('Custom message.') | ||
expect(rule.$message({ $params: {} })).toBe('Custom message.') | ||
}) | ||
}) |