const root = '../../';
jest.useFakeTimers();
describe('iat plugin', function(){
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-iat.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['iat']).not.toBe('undefined');
});
test('displays image by default', function(){
var trial = {
type: 'iat',
stimulus: '../media/blue.png'
}
jsPsych.init({
timeline: [trial]
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
});
test('displays html when is_html is true', function(){
var trial = {
type: 'iat',
stimulus: '
hello
', is_html: true } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().innerHTML).toBe('hello
hello
', is_html: true } jsPsych.init({ timeline: [trial] }); document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32})); document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32})); expect(jsPsych.getDisplayElement().innerHTML).toBe(''); }); test('display should not clear after key press when choices is jsPsych.NO_KEYS', function(){ var trial = { type: 'iat', stimulus: 'hello
', is_html: true, choices: jsPsych.NO_KEYS } jsPsych.init({ timeline: [trial] }); document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32})); document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32})); expect(jsPsych.getDisplayElement().innerHTML).toBe('hello
hello
', is_html: true, choices: ['f'] } jsPsych.init({ timeline: [trial] }); document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32})); document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32})); expect(jsPsych.getDisplayElement().innerHTML).toBe('hello
hello
', is_html: true, prompt: 'hello
hello
', is_html: true, display_feedback: false, timing_response: 500 } jsPsych.init({ timeline: [trial] }); expect(jsPsych.getDisplayElement().innerHTML).toBe('hello
hello
', is_html: true, response_ends_trial: false, display_feedback: false, timing_response: 500 } jsPsych.init({ timeline: [trial] }); document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 70})); document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 70})); expect(jsPsych.getDisplayElement().innerHTML).toBe('hello
hello
'; }, is_html: function(){ return true; }, choices: function(){ return ['j']; }, prompt: function(){ return 'hello
hello
hello
hello