-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for numbers and symbols to entriesFromList #492
- Loading branch information
1 parent
5869f95
commit 2edbd22
Showing
4 changed files
with
51 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 17 additions & 6 deletions
23
library/src/utils/entriesFromList/entriesFromList.test-d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { describe, expectTypeOf, test } from 'vitest'; | ||
import { string } from '../../schemas/index.ts'; | ||
import { arrayAsync, string } from '../../schemas/index.ts'; | ||
import { entriesFromList } from './entriesFromList.ts'; | ||
|
||
describe('entriesFromList', () => { | ||
test('should return object entries', () => { | ||
const schema = string(); | ||
expectTypeOf(entriesFromList(['foo', 'bar', 'baz'], schema)).toEqualTypeOf< | ||
Record<'foo' | 'bar' | 'baz', typeof schema> | ||
>(); | ||
describe('should return object entries', () => { | ||
const symbol = Symbol(); | ||
|
||
test('for sync schemas', () => { | ||
const schema = string(); | ||
expectTypeOf(entriesFromList(['foo', 123, symbol], schema)).toEqualTypeOf< | ||
Record<'foo' | 123 | typeof symbol, typeof schema> | ||
>(); | ||
}); | ||
|
||
test('for async schemas', () => { | ||
const schema = arrayAsync(string()); | ||
expectTypeOf(entriesFromList(['foo', 123, symbol], schema)).toEqualTypeOf< | ||
Record<'foo' | 123 | typeof symbol, typeof schema> | ||
>(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { string } from '../../schemas/index.ts'; | ||
import { arrayAsync, string } from '../../schemas/index.ts'; | ||
import { entriesFromList } from './entriesFromList.ts'; | ||
|
||
describe('entriesFromList', () => { | ||
test('should return object entries', () => { | ||
const schema = string(); | ||
expect(entriesFromList(['foo', 'bar', 'baz'], schema)).toEqual({ | ||
foo: schema, | ||
bar: schema, | ||
baz: schema, | ||
describe('should return object entries', () => { | ||
const symbol = Symbol(); | ||
|
||
test('for sync schemas', () => { | ||
const schema = string(); | ||
expect(entriesFromList(['foo', 123, symbol], schema)).toEqual({ | ||
foo: schema, | ||
[123]: schema, | ||
[symbol]: schema, | ||
}); | ||
}); | ||
|
||
test('for async schemas', () => { | ||
const schema = arrayAsync(string()); | ||
expect(entriesFromList(['foo', 123, symbol], schema)).toEqual({ | ||
foo: schema, | ||
[123]: schema, | ||
[symbol]: schema, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters