jsPsych/packages/jspsych/tests/core/default-iti.test.ts
2021-07-06 17:55:42 +02:00

50 lines
1.2 KiB
TypeScript

import { jest } from "@jest/globals";
import htmlKeyboardResponse from "@jspsych/plugin-html-keyboard-response";
import jsPsych from "../../src";
import { pressKey } from "../utils";
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.init({ 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.init({ 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");
});
});