Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix fallbackAsync for async arg & add relevant tests #732

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the library will be documented in this file.
- Add `base64` action to validate Base64 strings (pull request #644)
- Refactor `HEXADECIMAL_REGEX` (pull request #666)
- Change `EMOJI_REGEX` to be more accurate and strict (pull request #666)
- Fix bug in `fallbackAsync` method for async schemas (pull request #732)

## v0.36.0 (July 05, 2024)

Expand Down
14 changes: 10 additions & 4 deletions library/src/methods/fallback/fallbackAsync.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { describe, expect, test } from 'vitest';
import { transform } from '../../actions/index.ts';
import { transformAsync } from '../../actions/index.ts';
import { number } from '../../schemas/index.ts';
import { pipe } from '../pipe/index.ts';
import { pipeAsync } from '../pipe/index.ts';
import {
fallbackAsync,
type SchemaWithFallbackAsync,
} from './fallbackAsync.ts';

describe('fallbackAsync', () => {
describe('should return schema object', () => {
const schema = pipe(number(), transform(String));
const schema = pipeAsync(
number(),
transformAsync(async (input) => String(input))
);
type Schema = typeof schema;
const baseSchema: Omit<
SchemaWithFallbackAsync<Schema, never>,
Expand Down Expand Up @@ -45,7 +48,10 @@ describe('fallbackAsync', () => {
});

const schema = fallbackAsync(
pipe(number(), transform(String)),
pipeAsync(
number(),
transformAsync(async (input) => String(input))
),
async () => '123'
);

Expand Down
2 changes: 1 addition & 1 deletion library/src/methods/fallback/fallbackAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function fallbackAsync<
fallback,
async: true,
async _run(dataset, config) {
schema._run(dataset, config);
await schema._run(dataset, config);
return dataset.issues
? // @ts-expect-error
{ typed: true, value: await getFallback(this, dataset, config) }
Expand Down