Skip to content

Commit

Permalink
feat: added cases for whitespace and removed the isRequired cases
Browse files Browse the repository at this point in the history
  • Loading branch information
atharva3010 committed Mar 5, 2021
1 parent 4b50b61 commit 6206b36
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/unit/rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,18 @@ describe('number', () => {
describe('required', () => {
it('fails on empty string', async () => expect(await rules.required({ value: '' })).toBe(false))

it('fails with only whitespace as value when second argument is "trim"', async () => expect(await rules.required({ value: ' ' }, 'trim')).toBe(false))

it('fails on empty array', async () => expect(await rules.required({ value: [] })).toBe(false))

it('fails on empty object', async () => expect(await rules.required({ value: {} })).toBe(false))

it('fails on null', async () => expect(await rules.required({ value: null })).toBe(false))

it('passes with only whitespace as value', async () => expect(await rules.required({ value: ' ' })).toBe(true))

it('passes with only whitespace as value when second argument is not "trim"', async () => expect(await rules.required({ value: ' ' }, 'pre')).toBe(true))

it('passes with the number zero', async () => expect(await rules.required({ value: 0 })).toBe(true))

it('passes with the boolean false', async () => expect(await rules.required({ value: false })).toBe(true))
Expand All @@ -462,10 +468,6 @@ describe('required', () => {

it('passes with a non empty object', async () => expect(await rules.required({ value: { a: 'b' } })).toBe(true))

it('passes with empty value if second argument is false', async () => expect(await rules.required({ value: '' }, false)).toBe(true))

it('passes with empty value if second argument is false string', async () => expect(await rules.required({ value: '' }, 'false')).toBe(true))

it('passes with FileUpload', async () => expect(await rules.required({ value: new FileUpload({ files: [{ name: 'j.png' }] }) })).toBe(true))

it('fails with empty FileUpload', async () => expect(await rules.required({ value: new FileUpload({ files: [] }) })).toBe(false))
Expand Down

0 comments on commit 6206b36

Please sign in to comment.