Skip to content

Commit

Permalink
Merge pull request #732 from EltonLobo07/fix/fallbackAsync-async-arg
Browse files Browse the repository at this point in the history
fix `fallbackAsync` for async arg & add relevant tests
  • Loading branch information
fabian-hiller authored Jul 21, 2024
2 parents 4381e20 + 659f687 commit 7908989
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
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

0 comments on commit 7908989

Please sign in to comment.