jsPsych/packages/plugin-categorize-html/src/index.spec.ts
Josh de Leeuw 522aa2cdbf
Adding a simulation mode (#2287)
Implements simulation mode in the core library, supporting API features, and plugin support in most plugins.
2021-11-23 15:12:30 -05:00

69 lines
1.6 KiB
TypeScript

import { pressKey, simulateTimeline, startTimeline } from "@jspsych/test-utils";
import categorizeHtml from ".";
jest.useFakeTimers();
describe("categorize-html plugin", () => {
test("basic functionality works", async () => {
const { getHTML, expectFinished } = await startTimeline([
{
type: categorizeHtml,
stimulus: "FOO",
key_answer: "d",
choices: ["p", "d"],
},
]);
expect(getHTML()).toMatch("FOO");
pressKey("d");
expect(getHTML()).toMatch("Correct");
jest.advanceTimersByTime(2000);
await expectFinished();
});
});
describe("categorize-html plugin simulation", () => {
test("data-only mode works", async () => {
const { getData, expectFinished } = await simulateTimeline([
{
type: categorizeHtml,
stimulus: "FOO",
key_answer: "d",
choices: ["p", "d"],
},
]);
await expectFinished();
const data = getData().values()[0];
expect(["p", "d"].includes(data.response)).toBe(true);
expect(data.correct).toBe(data.response == "d");
});
test("visual mode works", async () => {
const { getData, expectRunning, expectFinished } = await simulateTimeline(
[
{
type: categorizeHtml,
stimulus: "FOO",
key_answer: "d",
choices: ["p", "d"],
},
],
"visual"
);
await expectRunning();
jest.runAllTimers();
await expectFinished();
const data = getData().values()[0];
expect(["p", "d"].includes(data.response)).toBe(true);
expect(data.correct).toBe(data.response == "d");
});
});