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.
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { jest } from "@jest/globals";
|
|
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
|
|
|
|
import { JsPsych, initJsPsych } from "../../src";
|
|
import { pressKey } from "../utils";
|
|
|
|
let jsPsych: JsPsych;
|
|
|
|
jest.useFakeTimers();
|
|
|
|
describe("default iti parameter", function () {
|
|
test("has a default value of 0", function () {
|
|
var t = {
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "foo",
|
|
};
|
|
|
|
var t2 = {
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "bar",
|
|
};
|
|
|
|
jsPsych = initJsPsych({ timeline: [t, t2] });
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("foo");
|
|
pressKey("a");
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("bar");
|
|
pressKey("a");
|
|
});
|
|
|
|
test("creates a correct delay when set", function () {
|
|
var t = {
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "foo",
|
|
};
|
|
|
|
var t2 = {
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "bar",
|
|
};
|
|
|
|
jsPsych = initJsPsych({ timeline: [t, t2], default_iti: 100 });
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("foo");
|
|
pressKey("a");
|
|
expect(jsPsych.getDisplayElement().innerHTML).not.toMatch("bar");
|
|
jest.advanceTimersByTime(100);
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("bar");
|
|
pressKey("a");
|
|
});
|
|
});
|