From b67d4a4881c8a3d1de536c0acb659337b27eceeb Mon Sep 17 00:00:00 2001 From: Becky Gilbert Date: Wed, 2 Dec 2020 12:11:38 -0800 Subject: [PATCH] add auto preload test --- .../plugin-video-button-response.test.js | 17 +++++++++++++++++ .../plugin-video-keyboard-response.test.js | 17 +++++++++++++++++ .../plugin-video-slider-response.test.js | 16 ++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/tests/plugins/plugin-video-button-response.test.js b/tests/plugins/plugin-video-button-response.test.js index 7a0c2ad7..a35aada6 100644 --- a/tests/plugins/plugin-video-button-response.test.js +++ b/tests/plugins/plugin-video-button-response.test.js @@ -13,4 +13,21 @@ describe('video-button-response plugin', function(){ expect(typeof window.jsPsych.plugins['video-button-response']).not.toBe('undefined'); }); + test('video preloading initiates automatically', function(){ + const preload_spy = jest.spyOn(jsPsych.pluginAPI, 'registerPreload'); + const console_spy = jest.spyOn(console, 'warn'); + var trial = { + type: 'video-button-response', + stimulus: [root + 'tests/media/sample_video.mp4'], + choices: ['y'] + } + jsPsych.init({ + timeline: [trial] + }); + //expect(preload_spy).toHaveBeenCalled(); // NOT WORKING + expect(console_spy).not.toHaveBeenCalled(); + preload_spy.mockRestore(); + console_spy.mockRestore(); + }); + }); diff --git a/tests/plugins/plugin-video-keyboard-response.test.js b/tests/plugins/plugin-video-keyboard-response.test.js index 9ca09bd5..a0194832 100644 --- a/tests/plugins/plugin-video-keyboard-response.test.js +++ b/tests/plugins/plugin-video-keyboard-response.test.js @@ -13,4 +13,21 @@ describe('video-keyboard-response plugin', function(){ expect(typeof window.jsPsych.plugins['video-keyboard-response']).not.toBe('undefined'); }); + test('video preloading initiates automatically', function(){ + const preload_spy = jest.spyOn(jsPsych.pluginAPI, 'registerPreload'); + const console_spy = jest.spyOn(console, 'warn'); + var trial = { + type: 'video-keyboard-response', + stimulus: [root + 'tests/media/sample_video.mp4'], + choices: jsPsych.ALL_KEYS + } + jsPsych.init({ + timeline: [trial] + }); + //expect(preload_spy).toHaveBeenCalled(); // NOT WORKING + expect(console_spy).not.toHaveBeenCalled(); + preload_spy.mockRestore(); + console_spy.mockRestore(); + }); + }); diff --git a/tests/plugins/plugin-video-slider-response.test.js b/tests/plugins/plugin-video-slider-response.test.js index add93c8c..948ccaf6 100644 --- a/tests/plugins/plugin-video-slider-response.test.js +++ b/tests/plugins/plugin-video-slider-response.test.js @@ -13,4 +13,20 @@ describe('video-slider-response plugin', function(){ expect(typeof window.jsPsych.plugins['video-slider-response']).not.toBe('undefined'); }); + test('video preloading initiates automatically', function(){ + const preload_spy = jest.spyOn(jsPsych.pluginAPI, 'registerPreload'); + const console_spy = jest.spyOn(console, 'warn'); + var trial = { + type: 'video-slider-response', + stimulus: [root + 'tests/media/sample_video.mp4'] + } + jsPsych.init({ + timeline: [trial] + }); + //expect(preload_spy).toHaveBeenCalled(); // NOT WORKING + expect(console_spy).not.toHaveBeenCalled(); + preload_spy.mockRestore(); + console_spy.mockRestore(); + }); + });