jsPsych/packages/jspsych/tests/core/default-parameters.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

58 lines
1.3 KiB
TypeScript

import surveyText from "@jspsych/plugin-survey-text";
import { JsPsych, initJsPsych } from "../../src";
let jsPsych: JsPsych;
describe("nested defaults", function () {
test("work in basic situation", function () {
var t = {
type: surveyText,
questions: [
{
prompt: "Question 1.",
},
{
prompt: "Question 2.",
},
],
};
jsPsych = initJsPsych({ timeline: [t] });
var display = jsPsych.getDisplayElement();
expect(display.querySelector("input").placeholder).toBe("");
expect(display.querySelector("input").size).toBe(40);
});
test("safe against extending the array.prototype (issue #989)", function () {
// @ts-expect-error
Array.prototype.qq = jest.fn();
const spy = jest.spyOn(console, "error").mockImplementation();
var t = {
type: surveyText,
questions: [
{
prompt: "Question 1.",
},
{
prompt: "Question 2.",
},
],
};
jsPsych = initJsPsych({ timeline: [t] });
var display = jsPsych.getDisplayElement();
expect(display.querySelector("input").placeholder).toBe("");
expect(display.querySelector("input").size).toBe(40);
expect(spy).not.toHaveBeenCalled();
spy.mockRestore();
});
});