From 8c998ef249c7a4b080e47be8ebc4bf54045bd054 Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Thu, 30 May 2019 16:50:02 -0400 Subject: [PATCH] add test for nested timelines and endCurrentTimeline (#600) --- tests/jsPsych/timelines.test.js | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/jsPsych/timelines.test.js b/tests/jsPsych/timelines.test.js index 554803c9..952b07c1 100644 --- a/tests/jsPsych/timelines.test.js +++ b/tests/jsPsych/timelines.test.js @@ -253,4 +253,51 @@ describe('endCurrentTimeline', function(){ }); + test('works inside nested timelines', function(){ + var t = { + timeline: [ + { + timeline: [ + { + type: 'html-keyboard-response', + stimulus: 'foo', + on_finish: function(){ + jsPsych.endCurrentTimeline(); + } + }, + { + type: 'html-keyboard-response', + stimulus: 'skip me!' + } + ] + }, + { + type: 'html-keyboard-response', + stimulus: 'bar' + } + ] + } + + var t2 = { + type: 'html-keyboard-response', + stimulus: 'woo' + } + + jsPsych.init({ + timeline: [t, t2] + }); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo'); + + utils.pressKey(32); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('bar'); + + utils.pressKey(32); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('woo'); + + utils.pressKey(32); + }) + });