-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgenType.test.js
More file actions
26 lines (23 loc) · 1.03 KB
/
genType.test.js
File metadata and controls
26 lines (23 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { getResourceTypeReference, getNewKeyTypeFromBatchKeySetType, getLoaderTypeKey } from '../src/genType';
it('getResourceTypeReference converts a resource path to a valid reference', () => {
expect(getResourceTypeReference(null, ['foo', 'bar', 'baz'])).toBe("ResourcesType['foo']['bar']['baz']");
});
it('getNewKeyTypeFromBatchKeySetType returns a newKey type with a valid value', () => {
expect(getNewKeyTypeFromBatchKeySetType('bKey', "ResourcesType['foo']['bar']['baz']")).toBe(
`Parameters<ResourcesType['foo']['bar']['baz']['bKey']['has']>[0]`,
);
});
it('getLoaderTypeKey forces a nullable batchKey to be strictly non-nullable', () => {
expect(
getLoaderTypeKey(
{
isBatchResource: true,
newKey: 'test_id',
batchKey: 'test_ids',
},
['a', 'b'],
),
).toBe(
`Omit<Parameters<ResourcesType['a']['b']>[0], 'test_ids'> & { test_id: NonNullable<Parameters<ResourcesType['a']['b']>[0]['test_ids']>[0] }`,
);
});