import { pressKey, simulateTimeline, startTimeline } from "@jspsych/test-utils"; import { initJsPsych } from "jspsych"; import audioKeyboardResponse from "."; jest.useFakeTimers(); describe("audio-keyboard-response simulation", () => { test("data mode works", async () => { const timeline = [ { type: audioKeyboardResponse, stimulus: "foo.mp3", }, ]; const { expectFinished, getData } = await simulateTimeline(timeline); await expectFinished(); expect(getData().values()[0].rt).toBeGreaterThan(0); expect(typeof getData().values()[0].response).toBe("string"); }); // can't run this until we mock Audio elements. test.skip("visual mode works", async () => { const jsPsych = initJsPsych({ use_webaudio: false }); const timeline = [ { type: audioKeyboardResponse, stimulus: "foo.mp3", prompt: "foo", }, ]; const { expectFinished, expectRunning, getHTML, getData } = await simulateTimeline( timeline, "visual", {}, jsPsych ); await expectRunning(); expect(getHTML()).toContain("foo"); jest.runAllTimers(); await expectFinished(); expect(getData().values()[0].rt).toBeGreaterThan(0); expect(typeof getData().values()[0].response).toBe("string"); }); });