jsPsych/packages/jspsych/tests/pluginAPI/preloads.test.ts
bjoluc 8cfbba526a Use classes to avoid global state
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.
2021-07-12 18:15:37 +02:00

38 lines
869 B
TypeScript

import imageKeyboardResponse from "@jspsych/plugin-image-keyboard-response";
import { JsPsych, initJsPsych } from "../../src";
let jsPsych: JsPsych;
describe("getAutoPreloadList", function () {
test("gets whole timeline when no argument provided", function () {
var t = {
type: imageKeyboardResponse,
stimulus: "img/foo.png",
render_on_canvas: false,
};
var timeline = [t];
jsPsych = initJsPsych({
timeline: timeline,
});
var images = jsPsych.pluginAPI.getAutoPreloadList().images;
expect(images[0]).toBe("img/foo.png");
});
test("works with images", function () {
var t = {
type: imageKeyboardResponse,
stimulus: "img/foo.png",
};
var timeline = [t];
var images = jsPsych.pluginAPI.getAutoPreloadList(timeline).images;
expect(images[0]).toBe("img/foo.png");
});
});