github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/models/utils.spec.ts (about) 1 import { z, ZodError } from 'zod'; 2 import { Result } from '@webapp/util/fp'; 3 import { modelToResult } from '@webapp/models/utils'; 4 5 const fooModel = z.array(z.string()); 6 7 describe('modelToResult', () => { 8 it('parses unkown object', () => { 9 const got = modelToResult(fooModel, [] as unknown); 10 expect(got).toMatchObject(Result.ok([])); 11 }); 12 13 it('gives an error when object cant be parsed', () => { 14 const got = modelToResult(fooModel, null); 15 16 expect(got.isErr).toBe(true); 17 18 // We don't care exactly about the error format, only that it's a ZodError 19 expect((got as any).error instanceof ZodError).toBe(true); 20 }); 21 });