const utils = require('../testing-utils.js'); const root = '../../'; jest.useFakeTimers(); describe('image-slider-response', function(){ beforeEach(function(){ require(root + 'jspsych.js'); require(root + 'plugins/jspsych-image-slider-response.js'); }); test('loads correctly', function(){ expect(typeof window.jsPsych.plugins['image-slider-response']).not.toBe('undefined'); }); test('displays image stimulus', function(done){ var trial = { type: 'image-slider-response', stimulus: '../media/blue.png', labels: ['left', 'right'], button_label: 'button', on_load: function(){ expect(jsPsych.getDisplayElement().innerHTML).toMatch('
This is a prompt
' } jsPsych.init({ timeline: [trial], auto_preload: false }); expect(jsPsych.getDisplayElement().innerHTML).toMatch('This is a prompt
'); utils.clickTarget(document.querySelector('#jspsych-image-slider-response-next')); }); test('should hide stimulus if stimulus_duration is set', function(){ var trial = { type: 'image-slider-response', stimulus: '../media/blue.png', labels: ['left', 'right'], button_label: 'button', stimulus_duration: 500 } jsPsych.init({ timeline: [trial], auto_preload: false }); expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-slider-response-stimulus').style.visibility).toMatch(""); jest.runTimersToTime(500); expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-slider-response-stimulus').style.visibility).toMatch("hidden"); utils.clickTarget(document.querySelector('#jspsych-image-slider-response-next')); }); test('should end trial when trial duration is reached', function(){ var trial = { type: 'image-slider-response', stimulus: '../media/blue.png', labels: ['left', 'right'], button_label: 'button', trial_duration: 500 } jsPsych.init({ timeline: [trial], auto_preload: false }); expect(jsPsych.getDisplayElement().innerHTML).toMatch('