From c7b3762c0a51539e42462391201a5ba12fdcbf0c Mon Sep 17 00:00:00 2001 From: Becky Gilbert Date: Thu, 3 Dec 2020 09:18:07 -0800 Subject: [PATCH] fix registerPreload test --- tests/plugins/plugin-video-button-response.test.js | 6 ++++-- tests/plugins/plugin-video-keyboard-response.test.js | 6 ++++-- tests/plugins/plugin-video-slider-response.test.js | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/plugins/plugin-video-button-response.test.js b/tests/plugins/plugin-video-button-response.test.js index a35aada6..691d1d96 100644 --- a/tests/plugins/plugin-video-button-response.test.js +++ b/tests/plugins/plugin-video-button-response.test.js @@ -6,16 +6,18 @@ describe('video-button-response plugin', function(){ beforeEach(function(){ require(root + 'jspsych.js'); - require(root + 'plugins/jspsych-video-button-response.js'); + // don't load plugin here - need to spy on registerPreload before its called }); test('loads correctly', function(){ + require(root + 'plugins/jspsych-video-button-response.js'); 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'); + require(root + 'plugins/jspsych-video-button-response.js'); var trial = { type: 'video-button-response', stimulus: [root + 'tests/media/sample_video.mp4'], @@ -24,7 +26,7 @@ describe('video-button-response plugin', function(){ jsPsych.init({ timeline: [trial] }); - //expect(preload_spy).toHaveBeenCalled(); // NOT WORKING + expect(preload_spy).toHaveBeenCalled(); 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 a0194832..03daca0d 100644 --- a/tests/plugins/plugin-video-keyboard-response.test.js +++ b/tests/plugins/plugin-video-keyboard-response.test.js @@ -6,16 +6,18 @@ describe('video-keyboard-response plugin', function(){ beforeEach(function(){ require(root + 'jspsych.js'); - require(root + 'plugins/jspsych-video-keyboard-response.js'); + // don't load plugin here - need to spy on registerPreload before its called }); test('loads correctly', function(){ + require(root + 'plugins/jspsych-video-keyboard-response.js'); 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'); + require(root + 'plugins/jspsych-video-keyboard-response.js'); var trial = { type: 'video-keyboard-response', stimulus: [root + 'tests/media/sample_video.mp4'], @@ -24,7 +26,7 @@ describe('video-keyboard-response plugin', function(){ jsPsych.init({ timeline: [trial] }); - //expect(preload_spy).toHaveBeenCalled(); // NOT WORKING + expect(preload_spy).toHaveBeenCalled(); 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 948ccaf6..8a0d14f4 100644 --- a/tests/plugins/plugin-video-slider-response.test.js +++ b/tests/plugins/plugin-video-slider-response.test.js @@ -6,16 +6,18 @@ describe('video-slider-response plugin', function(){ beforeEach(function(){ require(root + 'jspsych.js'); - require(root + 'plugins/jspsych-video-slider-response.js'); + // don't load plugin here - need to spy on registerPreload before its called }); test('loads correctly', function(){ + require(root + 'plugins/jspsych-video-slider-response.js'); 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'); + require(root + 'plugins/jspsych-video-slider-response.js'); var trial = { type: 'video-slider-response', stimulus: [root + 'tests/media/sample_video.mp4'] @@ -23,7 +25,7 @@ describe('video-slider-response plugin', function(){ jsPsych.init({ timeline: [trial] }); - //expect(preload_spy).toHaveBeenCalled(); // NOT WORKING + expect(preload_spy).toHaveBeenCalled(); expect(console_spy).not.toHaveBeenCalled(); preload_spy.mockRestore(); console_spy.mockRestore();