diff --git a/tests/jsPsych/events.test.js b/tests/jsPsych/events.test.js index ef19b8c4..7d95de4f 100644 --- a/tests/jsPsych/events.test.js +++ b/tests/jsPsych/events.test.js @@ -399,6 +399,57 @@ describe('on_timeline_finish', function(){ expect(on_finish_fn).not.toHaveBeenCalled(); utils.pressKey(32); expect(on_finish_fn).toHaveBeenCalled(); + }); + + test('should fire once even with timeline variables', function(){ + + var on_finish_fn = jest.fn(); + + var tvs = [{ + x: 1, + x: 2, + }] + + var mini_timeline = { + timeline: [ + { + type: 'html-keyboard-response', + stimulus: 'foo' + } + ], + on_timeline_finish: on_finish_fn, + timeline_variables: tvs + } + + jsPsych.init({timeline: [mini_timeline]}); + + utils.pressKey(32); + utils.pressKey(32); + expect(on_finish_fn.mock.calls.length).toBe(1); + + }) + + test('should fire once even with repetitions', function(){ + + var on_finish_fn = jest.fn(); + + var mini_timeline = { + timeline: [ + { + type: 'html-keyboard-response', + stimulus: 'foo' + } + ], + on_timeline_finish: on_finish_fn, + repetitions: 2 + } + + jsPsych.init({timeline: [mini_timeline]}); + + utils.pressKey(32); + utils.pressKey(32); + expect(on_finish_fn.mock.calls.length).toBe(1); + }) }) @@ -434,4 +485,57 @@ describe('on_timeline_start', function(){ expect(on_start_fn.mock.calls.length).toBe(1); }) + + test('should fire once even with timeline variables', function(){ + + var on_start_fn = jest.fn(); + + var tvs = [{ + x: 1, + x: 2, + }] + + var mini_timeline = { + timeline: [ + { + type: 'html-keyboard-response', + stimulus: 'foo' + } + ], + on_timeline_start: on_start_fn, + timeline_variables: tvs + } + + jsPsych.init({timeline: [mini_timeline]}); + + expect(on_start_fn).toHaveBeenCalled(); + utils.pressKey(32); + utils.pressKey(32); + expect(on_start_fn.mock.calls.length).toBe(1); + + }) + + test('should fire once even with repetitions', function(){ + + var on_start_fn = jest.fn(); + + var mini_timeline = { + timeline: [ + { + type: 'html-keyboard-response', + stimulus: 'foo' + } + ], + on_timeline_start: on_start_fn, + repetitions: 2 + } + + jsPsych.init({timeline: [mini_timeline]}); + + expect(on_start_fn).toHaveBeenCalled(); + utils.pressKey(32); + utils.pressKey(32); + expect(on_start_fn.mock.calls.length).toBe(1); + + }) }) \ No newline at end of file