mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Merge pull request #3477 from rkilpadi/main
Improve error message for missing type parameter
This commit is contained in:
commit
9d8597f8c7
5
.changeset/large-flies-check.md
Normal file
5
.changeset/large-flies-check.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"jspsych": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add informative error message when a trial is missing the `type` parameter
|
@ -36,6 +36,16 @@ describe("Trial", () => {
|
|||||||
return 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(
|
||||||
|
"\"Plugin not recognized. Please provide a valid plugin using the 'type' parameter.\""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
describe("run()", () => {
|
describe("run()", () => {
|
||||||
it("instantiates the corresponding plugin", async () => {
|
it("instantiates the corresponding plugin", async () => {
|
||||||
const trial = createTrial({ type: TestPlugin });
|
const trial = createTrial({ type: TestPlugin });
|
||||||
|
@ -35,7 +35,12 @@ export class Trial extends TimelineNode {
|
|||||||
|
|
||||||
this.trialObject = deepCopy(description);
|
this.trialObject = deepCopy(description);
|
||||||
this.pluginClass = this.getParameterValue("type", { evaluateFunctions: false });
|
this.pluginClass = this.getParameterValue("type", { evaluateFunctions: false });
|
||||||
this.pluginInfo = this.pluginClass["info"];
|
this.pluginInfo = this.pluginClass?.["info"];
|
||||||
|
if (!this.pluginInfo) {
|
||||||
|
throw new Error(
|
||||||
|
"Plugin not recognized. Please provide a valid plugin using the 'type' parameter."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!("version" in this.pluginInfo) && !("data" in this.pluginInfo)) {
|
if (!("version" in this.pluginInfo) && !("data" in this.pluginInfo)) {
|
||||||
console.warn(
|
console.warn(
|
||||||
|
Loading…
Reference in New Issue
Block a user