0.0.3 • Published 2 years ago

z-expect v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Z-Expect — Zod + Jest Expect

šŸŽµ WIP WIP WIP that's a Work in Progress šŸŽµ

import { z, expect } from 'z-expect'

// Throws exception or returns void. No need to use a test runner.
expect(await response.json()).toMatchObject({
  results: [{ 1: 1 }],
  meta: { duration: z.number().gt(0), served_by: 'x-server-123' },
  success: true,
})

This gets converted to:

const schema = z.object({
  results: z.tuple([
    z.object({1: z.literal(1)})
  ]),
  meta: z.object({
    duration: z.number().gt(0),
    served_by: z.literal('x-server-123')
  }),
  success: z.literal(true),
})

schema.parse(await response.json())
0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago