Skip to content

Commit

Permalink
Add test case for #3412
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoluc committed Oct 12, 2024
1 parent a411b88 commit 05d59d1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/jspsych/src/timeline/Trial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ describe("Trial", () => {

// This should work:
await createTrial({ type: TestPlugin, stringArray: [] }).run();
await createTrial({ type: TestPlugin, stringArray: new TimelineVariable("a") });

// This shouldn't:
await expect(
Expand Down Expand Up @@ -436,6 +437,8 @@ describe("Trial", () => {
return TestPlugin;
case "x":
return "foo";
case "y":
return ["foo", "bar"];
default:
return undefined;
}
Expand All @@ -444,17 +447,19 @@ describe("Trial", () => {
const trial = createTrial({
type: new TimelineVariable("t"),
requiredString: new TimelineVariable("x"),
stringArray: new TimelineVariable("y"),
requiredComplexNested: { requiredChild: () => new TimelineVariable("x") },
requiredComplexNestedArray: [{ requiredChild: () => new TimelineVariable("x") }],
});

await trial.run();

// The `x` timeline variables should have been replaced with `foo`
// The `x` and `y` timeline variables should have been evaluated
expect(trial.pluginInstance.trial).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
requiredString: "foo",
stringArray: ["foo", "bar"],
requiredComplexNested: expect.objectContaining({ requiredChild: "foo" }),
requiredComplexNestedArray: [expect.objectContaining({ requiredChild: "foo" })],
}),
Expand Down

0 comments on commit 05d59d1

Please sign in to comment.