|
|
|
|
@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest';
|
|
|
|
|
import { array, lazy, object, optional, string } from '../core';
|
|
|
|
|
import { createSchema } from '../core/schema';
|
|
|
|
|
import type { Schema } from '../core/types';
|
|
|
|
|
import { SiumAsyncSchemaError } from '../errors';
|
|
|
|
|
import { SiumAsyncSchemaError, SiumLazyResolvingError } from '../errors';
|
|
|
|
|
|
|
|
|
|
type TreeNode = {
|
|
|
|
|
value: string;
|
|
|
|
|
@ -219,8 +219,22 @@ describe('lazy()', () => {
|
|
|
|
|
expect(() => schema.decodeSync('x')).toThrow(SiumAsyncSchemaError);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws SiumLazyResolvingError when the thunk uses the proxy while resolving', () => {
|
|
|
|
|
const schema: Schema<string, string> = lazy(() => {
|
|
|
|
|
schema.decodeSync('x');
|
|
|
|
|
return string();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(() => schema.decodeSync('x')).toThrow(SiumLazyResolvingError);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws SiumLazyResolvingError when the thunk returns the same lazy proxy', () => {
|
|
|
|
|
const schema: Schema<string, string> = lazy(() => schema);
|
|
|
|
|
|
|
|
|
|
expect(() => schema.decodeSync('x')).toThrow(SiumLazyResolvingError);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('is re-exported by the core barrel', () => {
|
|
|
|
|
expect(lazy).toBeTypeOf('function');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|