Add test case for missing plugin type/info

This commit is contained in:
bjoluc 2025-01-06 14:57:58 +01:00
parent d8653b0760
commit 4035041967
2 changed files with 12 additions and 2 deletions

View File

@ -36,6 +36,16 @@ describe("Trial", () => {
return trial;
};
it("throws an error upon construction when the `type` parameter or plugin info object is undefined", () => {
for (const description of [{}, { type: {} }] as TrialDescription[]) {
expect(
() => new Trial(dependencies, description, timeline)
).toThrowErrorMatchingInlineSnapshot(
"\"Trial plugin not recognized. Please provide a valid plugin using the 'type' parameter.\""
);
}
});
describe("run()", () => {
it("instantiates the corresponding plugin", async () => {
const trial = createTrial({ type: TestPlugin });

View File

@ -35,12 +35,12 @@ export class Trial extends TimelineNode {
this.trialObject = deepCopy(description);
this.pluginClass = this.getParameterValue("type", { evaluateFunctions: false });
if (this.pluginClass === undefined || this.pluginClass["info"] === undefined) {
this.pluginInfo = this.pluginClass?.["info"];
if (!this.pluginInfo) {
throw new Error(
"Trial plugin not recognized. Please provide a valid plugin using the 'type' parameter."
);
}
this.pluginInfo = this.pluginClass["info"];
if (!("version" in this.pluginInfo) && !("data" in this.pluginInfo)) {
console.warn(