From 0b1b5c3cf90a7d8545c2a9dcf2a5dc1dcaf20afc Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Mon, 25 Jun 2018 15:18:40 -0400 Subject: [PATCH] add test for jsPsych.endExperiment() --- tests/jsPsych/endexperiment.test.js | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/jsPsych/endexperiment.test.js diff --git a/tests/jsPsych/endexperiment.test.js b/tests/jsPsych/endexperiment.test.js new file mode 100644 index 00000000..9b6dd16a --- /dev/null +++ b/tests/jsPsych/endexperiment.test.js @@ -0,0 +1,49 @@ +const utils = require('../testing-utils.js'); + +beforeEach(function(){ + require('../../jspsych.js'); + require('../../plugins/jspsych-html-keyboard-response'); +}); + +test('works on basic timeline', function(){ + var timeline = [ + { + type: 'html-keyboard-response', + stimulus: 'trial 1', + on_finish: function(){ + jsPsych.endExperiment('the end'); + } + }, + { + type: 'html-keyboard-response', + stimulus: 'trial 2' + } + ] + + jsPsych.init({timeline}); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('trial 1'); + + utils.pressKey(32); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('the end'); +}); + +test('works with looping timeline (#541)', function(){ + var timeline = [ + { + timeline: [{type: 'html-keyboard-response', stimulus: 'trial 1'}], + loop_function: function(){ + jsPsych.endExperiment('the end') + } + } + ] + + jsPsych.init({timeline}); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('trial 1'); + + utils.pressKey(32); + + expect(jsPsych.getDisplayElement().innerHTML).toMatch('the end'); +}); \ No newline at end of file