mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-13 09:08:13 +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.
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
|
|
|
|
import { JsPsych, initJsPsych } from "../../src";
|
|
import { pressKey } from "../utils";
|
|
|
|
let jsPsych: JsPsych;
|
|
|
|
// ideally, use fake timers for this test, but 'modern' timers that work
|
|
// with performance.now() break something in the first test. wait for fix?
|
|
//jest.useFakeTimers('modern');
|
|
//jest.useFakeTimers();
|
|
|
|
describe("minimum_valid_rt 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("correctly prevents fast responses when set", function (done) {
|
|
var t = {
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "foo",
|
|
};
|
|
|
|
var t2 = {
|
|
type: htmlKeyboardResponse,
|
|
stimulus: "bar",
|
|
};
|
|
|
|
jsPsych = initJsPsych({ timeline: [t, t2], minimum_valid_rt: 100 });
|
|
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("foo");
|
|
pressKey("a");
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("foo");
|
|
setTimeout(function () {
|
|
pressKey("a");
|
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch("bar");
|
|
pressKey("a");
|
|
done();
|
|
}, 100);
|
|
});
|
|
});
|