Skip to content

Commit

Permalink
add viewportRangeSchemaTest (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann authored Oct 9, 2023
1 parent 89a36ec commit 473a59b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/schemas/viewportRangeTokenSchema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {viewportRangeToken} from './viewportRangeToken'

describe('Schema: viewportRangeToken', () => {
const validToken = {
$value: '(max-width: calc({<namespace>.breakpoint.medium} - 0.02px))',
$type: 'custom-viewportRange',
$description: 'a number token',
}

it('parses valid number tokens', () => {
expect(viewportRangeToken.safeParse(validToken).success).toStrictEqual(true)
})

it('fails on invalid properties', () => {
// additional element
expect(
viewportRangeToken.safeParse({
...validToken,
additional: 1000,
}).success,
).toStrictEqual(false)
// invalid value
expect(
viewportRangeToken.safeParse({
...validToken,
value: 1000,
}).success,
).toStrictEqual(false)
// missing value
expect(
viewportRangeToken.safeParse({
$type: 'number',
}).success,
).toStrictEqual(false)
})

it('fails on wrong type', () => {
// invalid string
expect(
viewportRangeToken.safeParse({
...validToken,
$type: 'motion',
}).success,
).toStrictEqual(false)
// undefined
expect(
viewportRangeToken.safeParse({
...validToken,
$type: undefined,
}).success,
).toStrictEqual(false)
// no type
expect(
viewportRangeToken.safeParse({
$value: '(max-width: calc({<namespace>.breakpoint.medium} - 0.02px))',
}).success,
).toStrictEqual(false)
})
})

0 comments on commit 473a59b

Please sign in to comment.