Skip to content

Commit

Permalink
dimensionValue tests (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann authored Oct 8, 2023
1 parent 068dca0 commit 89a36ec
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/schemas/dimensionTokenSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {dimensionToken} from './dimensionToken'

describe('Schema: dimensionToken', () => {
const validToken = {
$value: '1px',
$type: 'dimension',
$description: 'a dimension token',
}

it('passes on valid values', () => {
expect(dimensionToken.safeParse(validToken).success).toStrictEqual(true)
expect(dimensionToken.safeParse({...validToken, $value: '1em'}).success).toStrictEqual(true)
expect(dimensionToken.safeParse({...validToken, $value: '1rem'}).success).toStrictEqual(true)
})

it('fails on invalid type', () => {
expect(dimensionToken.safeParse({...validToken, $type: 'stroke'}).success).toStrictEqual(false)
})

it('fails on invalid value', () => {
expect(dimensionToken.safeParse({...validToken, $value: 'wrong'}).success).toStrictEqual(false)
expect(dimensionToken.safeParse({...validToken, $value: '1%'}).success).toStrictEqual(false)
expect(dimensionToken.safeParse({...validToken, $value: undefined}).success).toStrictEqual(false)
expect(dimensionToken.safeParse({...validToken, $value: ''}).success).toStrictEqual(false)
expect(dimensionToken.safeParse({...validToken, $value: false}).success).toStrictEqual(false)
expect(dimensionToken.safeParse({...validToken, $value: 1}).success).toStrictEqual(false)
})
})
21 changes: 21 additions & 0 deletions src/schemas/dimensionValueSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {dimensionValue} from './dimensionValue'

describe('Schema: dimensionValue', () => {
it('passes on valid values', () => {
expect(dimensionValue.safeParse('1px').success).toStrictEqual(true)
expect(dimensionValue.safeParse('-1px').success).toStrictEqual(true)
expect(dimensionValue.safeParse('1em').success).toStrictEqual(true)
expect(dimensionValue.safeParse('1rem').success).toStrictEqual(true)
expect(dimensionValue.safeParse('0').success).toStrictEqual(true)
expect(dimensionValue.safeParse(0).success).toStrictEqual(true)
})

it('fails on invalid value', () => {
expect(dimensionValue.safeParse('1%').success).toStrictEqual(false)
expect(dimensionValue.safeParse(1).success).toStrictEqual(false)
expect(dimensionValue.safeParse('small').success).toStrictEqual(false)
expect(dimensionValue.safeParse('').success).toStrictEqual(false)
expect(dimensionValue.safeParse(false).success).toStrictEqual(false)
expect(dimensionValue.safeParse(undefined).success).toStrictEqual(false)
})
})

0 comments on commit 89a36ec

Please sign in to comment.