frontend-plugin-api: add test for blueprint param overloads
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { coreExtensionData } from './coreExtensionData';
|
||||
import {
|
||||
createExtensionBlueprint,
|
||||
createExtensionBlueprintParams,
|
||||
ExtensionBlueprintParams,
|
||||
} from './createExtensionBlueprint';
|
||||
import {
|
||||
createExtensionTester,
|
||||
@@ -1580,5 +1581,35 @@ describe('createExtensionBlueprint', () => {
|
||||
).get(testDataRef),
|
||||
).toBe(`21 31`);
|
||||
});
|
||||
|
||||
it('should support overloads', () => {
|
||||
const TestTransformExtensionBlueprint = createExtensionBlueprint({
|
||||
kind: 'test-extension',
|
||||
attachTo: { id: 'test', input: 'default' },
|
||||
output: [testDataRef],
|
||||
defineParams: (params => createExtensionBlueprintParams(params)) as {
|
||||
(params: { x: 1 }): ExtensionBlueprintParams<{ x: number }>;
|
||||
(params: { x: 2 }): ExtensionBlueprintParams<{ x: number }>;
|
||||
},
|
||||
factory(params) {
|
||||
return [testDataRef(`x: ${params.x}`)];
|
||||
},
|
||||
});
|
||||
|
||||
const extension = TestTransformExtensionBlueprint.make({
|
||||
params: define => define({ x: 1 }),
|
||||
});
|
||||
|
||||
expect(createExtensionTester(extension).get(testDataRef)).toBe(`x: 1`);
|
||||
|
||||
TestTransformExtensionBlueprint.make({
|
||||
params: define => define({ x: 2 }),
|
||||
});
|
||||
|
||||
TestTransformExtensionBlueprint.make({
|
||||
// @ts-expect-error doesn't match any overload
|
||||
params: define => define({ x: 3 }),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user