mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00

The `run()` method takes a timeline and returns a promise that is resolved when the experiment finishes. Hence, jsPsych can now be initialized without starting an experiment. This re-enables usage of `jsPsych.timelineVariable()` in timeline definitions and repairs exclusion checks and extension loading.
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
|
|
|
|
import { initJsPsych } from "../../src";
|
|
import { pressKey, startTimeline } from "../utils";
|
|
|
|
test("works on basic timeline", async () => {
|
|
const jsPsych = initJsPsych();
|
|
const { getHTML, expectFinished } = await startTimeline(
|
|
[
|
|
{
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "trial 1",
|
|
on_finish: () => {
|
|
jsPsych.endExperiment("the end");
|
|
},
|
|
},
|
|
{
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "trial 2",
|
|
},
|
|
],
|
|
jsPsych
|
|
);
|
|
|
|
expect(getHTML()).toMatch("trial 1");
|
|
pressKey("a");
|
|
expect(getHTML()).toMatch("the end");
|
|
await expectFinished();
|
|
});
|
|
|
|
test("works with looping timeline (#541)", async () => {
|
|
const jsPsych = initJsPsych();
|
|
const { getHTML, expectFinished } = await startTimeline(
|
|
[
|
|
{
|
|
timeline: [{ type: htmlKeyboardResponse, stimulus: "trial 1" }],
|
|
loop_function: () => {
|
|
jsPsych.endExperiment("the end");
|
|
},
|
|
},
|
|
],
|
|
jsPsych
|
|
);
|
|
|
|
expect(getHTML()).toMatch("trial 1");
|
|
pressKey("a");
|
|
expect(getHTML()).toMatch("the end");
|
|
await expectFinished();
|
|
});
|