mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00

Instead of a global `jsPsych` object, there is a `JsPsych` class now which can be instantiated with the parameters that were previously accepted by `jsPsych.init`. Upon instantiation, the `JsPsych` class also instantiates classes for stateful modules (`jsPsych.data` and `jsPsych.pluginAPI`) and passes relevant `JsPsych` instance information to them. Plugins are expected to be classes now that are instantiated for each trial and receive the `JsPsych` instance as their only constructor argument.
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
|
|
|
|
import { JsPsych, initJsPsych } from "../../src";
|
|
import { pressKey } from "../utils";
|
|
|
|
let jsPsych: JsPsych;
|
|
|
|
test("works on basic timeline", function () {
|
|
var timeline = [
|
|
{
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "trial 1",
|
|
on_finish: function () {
|
|
jsPsych.endExperiment("the end");
|
|
},
|
|
},
|
|
{
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "trial 2",
|
|
},
|
|
];
|
|
|
|
jsPsych = initJsPsych({ timeline });
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("trial 1");
|
|
|
|
pressKey("a");
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("the end");
|
|
});
|
|
|
|
test("works with looping timeline (#541)", function () {
|
|
var timeline = [
|
|
{
|
|
timeline: [{ type: htmlKeyboardResponse, stimulus: "trial 1" }],
|
|
loop_function: function () {
|
|
jsPsych.endExperiment("the end");
|
|
},
|
|
},
|
|
];
|
|
|
|
jsPsych = initJsPsych({ timeline });
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("trial 1");
|
|
|
|
pressKey("a");
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("the end");
|
|
});
|