mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00

The `run()` method takes a timeline and returns a promise that is resolved when the experiment finishes. Hence, jsPsych can now be initialized without starting an experiment. This re-enables usage of `jsPsych.timelineVariable()` in timeline definitions and repairs exclusion checks and extension loading.
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import { deepCopy, flatten, unique } from "../../src/modules/utils";
|
|
|
|
describe("unique", () => {
|
|
test("generates unique array when there are duplicates", () => {
|
|
var arr = [1, 1, 2, 2, 3, 3];
|
|
var out = unique(arr);
|
|
expect(out).toEqual([1, 2, 3]);
|
|
expect(out).not.toEqual(arr);
|
|
});
|
|
|
|
test("generates same array when there are no duplicates", () => {
|
|
var arr = [1, 2, 3];
|
|
var out = unique(arr);
|
|
expect(out).toEqual(arr);
|
|
});
|
|
});
|
|
|
|
describe("flatten", () => {
|
|
test("generates flat array from flat input", () => {
|
|
var arr = [1, 1, 2, 2, 3, 3];
|
|
var out = flatten(arr);
|
|
expect(out).toEqual(arr);
|
|
});
|
|
|
|
test("generates flat array from nested input", () => {
|
|
var arr = [1, [1, 2, 2], [3], 3];
|
|
var out = flatten(arr);
|
|
expect(out).toEqual([1, 1, 2, 2, 3, 3]);
|
|
});
|
|
});
|
|
|
|
describe("deepCopy", () => {
|
|
test("works for objects", () => {
|
|
var o = { a: 1, b: { c: 2, d: 3 } };
|
|
var o2 = deepCopy(o);
|
|
o2.b.c = 4;
|
|
expect(o.b.c).toBe(2);
|
|
});
|
|
test("works for objects with arrays", () => {
|
|
var o = { a: 1, b: [2, 3] };
|
|
var o2 = deepCopy(o);
|
|
o2.b[0] = 4;
|
|
expect(JSON.stringify(o2.b)).toBe(JSON.stringify([4, 3]));
|
|
expect(o.b[0]).toBe(2);
|
|
});
|
|
test("works for objects with functions", () => {
|
|
var c = 0;
|
|
var o = {
|
|
a: 1,
|
|
b: () => {
|
|
c = 2;
|
|
},
|
|
};
|
|
var o2 = deepCopy(o);
|
|
o2.b = () => {
|
|
c = 1;
|
|
};
|
|
o.b();
|
|
expect(c).toBe(2);
|
|
o2.b();
|
|
expect(c).toBe(1);
|
|
});
|
|
});
|