mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
jest upgrade, fixing tests to work with upgrade of jsdom
This commit is contained in:
parent
051c0839bf
commit
e89c947de7
6383
package-lock.json
generated
6383
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,9 +20,13 @@
|
||||
},
|
||||
"homepage": "https://github.com/jodeleeuw/jsPsych#readme",
|
||||
"devDependencies": {
|
||||
"jest": "^20.0.4"
|
||||
"jest": "^22.0.3"
|
||||
},
|
||||
"jest": {
|
||||
"resetModules": true
|
||||
"resetModules": true,
|
||||
"testEnvironmentOptions": {
|
||||
"fetchExternalResources": true,
|
||||
"pretendToBeVisual": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -338,9 +338,6 @@ describe('on_trial_start', function(){
|
||||
timeline: [trial],
|
||||
on_trial_start: function(trial){
|
||||
trial.stimulus = 'goodbye';
|
||||
},
|
||||
on_finish: function(){
|
||||
resolve(promise_data);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -150,8 +150,6 @@ describe('The data parameter', function(){
|
||||
utils.pressKey(32); // trial 1
|
||||
utils.pressKey(32); // trial 2
|
||||
|
||||
console.log(jsPsych.data.get().json())
|
||||
|
||||
expect(jsPsych.data.get().filter({added: true}).count()).toBe(1);
|
||||
expect(jsPsych.data.get().filter({added: false}).count()).toBe(1);
|
||||
});
|
||||
@ -183,8 +181,6 @@ describe('The data parameter', function(){
|
||||
utils.pressKey(32); // trial 1
|
||||
utils.pressKey(32); // trial 2
|
||||
|
||||
console.log(jsPsych.data.get().json())
|
||||
|
||||
expect(jsPsych.data.get().filter({added_copy: true}).count()).toBe(1);
|
||||
expect(jsPsych.data.get().filter({added_copy: false}).count()).toBe(1);
|
||||
});
|
||||
|
@ -15,6 +15,7 @@ describe('animation plugin', function(){
|
||||
|
||||
// SKIP FOR NOW
|
||||
test.skip('displays stimuli', function(){
|
||||
|
||||
var animation_sequence = ['img/face_1.jpg', 'img/face_2.jpg'];
|
||||
|
||||
var trial = {
|
||||
@ -23,7 +24,8 @@ describe('animation plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<img src="img/face_1.jpg" id="jspsych-animation-image"></img>');
|
||||
|
@ -22,7 +22,8 @@ describe('categorize-animation plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(500);
|
||||
@ -41,6 +42,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
@ -58,6 +60,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
@ -77,6 +80,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
@ -99,6 +103,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trials],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
@ -120,6 +125,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trials],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
@ -141,6 +147,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trials],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
@ -163,6 +170,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trials],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1000);
|
||||
@ -188,6 +196,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trials],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1000);
|
||||
@ -216,6 +225,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trials],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
@ -239,6 +249,7 @@ describe('categorize-animation plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trials],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
|
@ -21,6 +21,7 @@ describe('free-sort plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('src=\"img/happy_face_1.jpg\" data-src=\"img/happy_face_1.jpg\"'));
|
||||
@ -39,6 +40,7 @@ describe('free-sort plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('class=\"jspsych-free-sort-arena\" style=\"position: relative; width:700px; height:500px;'));
|
||||
@ -54,6 +56,7 @@ describe('free-sort plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src=\"img/happy_face_1.jpg\" data-src=\"img/happy_face_1.jpg\" class=\"jspsych-free-sort-draggable\" draggable=\"false\" style=\"position: absolute; cursor: move; width:200px; height:200px'));
|
||||
@ -68,6 +71,7 @@ describe('free-sort plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<p>This is a prompt</p>'));
|
||||
@ -83,6 +87,7 @@ describe('free-sort plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<p>This is a prompt</p><button id=\"jspsych-free-sort-done-btn\"'));
|
||||
@ -98,6 +103,7 @@ describe('free-sort plugin', function(){
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<button id=\"jspsych-free-sort-done-btn\" class=\"jspsych-btn\">Finito</button>'));
|
||||
|
@ -25,6 +25,8 @@ describe('html-keyboard-response', function(){
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('<div id="jspsych-html-keyboard-response-stimulus">this is html</div>');
|
||||
|
||||
utils.pressKey(70);
|
||||
});
|
||||
|
||||
test('display clears after key press', function(){
|
||||
@ -58,6 +60,8 @@ describe('html-keyboard-response', function(){
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<div id="jspsych-html-keyboard-response-stimulus">this is html</div><div id="foo">this is a prompt</div>'));
|
||||
|
||||
utils.pressKey(70);
|
||||
});
|
||||
|
||||
test('should hide stimulus if stimulus-duration is set', function(){
|
||||
@ -75,6 +79,7 @@ describe('html-keyboard-response', function(){
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-html-keyboard-response-stimulus').style.visibility).toMatch("");
|
||||
jest.runTimersToTime(500);
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-html-keyboard-response-stimulus').style.visibility).toMatch("hidden");
|
||||
utils.pressKey(70);
|
||||
});
|
||||
|
||||
test('should end trial when trial duration is reached', function(){
|
||||
@ -125,10 +130,10 @@ describe('html-keyboard-response', function(){
|
||||
timeline: [trial]
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<div id="jspsych-html-keyboard-response-stimulus">this is html</div>'));
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<div id="jspsych-html-keyboard-response-stimulus">this is html</div>'));
|
||||
|
||||
utils.pressKey(70);
|
||||
utils.pressKey(70);
|
||||
|
||||
expect(document.querySelector('#jspsych-html-keyboard-response-stimulus').className).toBe(' responded');
|
||||
expect(document.querySelector('#jspsych-html-keyboard-response-stimulus').className).toBe(' responded');
|
||||
});
|
||||
});
|
@ -1,4 +1,5 @@
|
||||
const root = '../../';
|
||||
const utils = require('../testing-utils.js');
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
@ -28,13 +29,13 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(/blue.png/);
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 70}));
|
||||
utils.pressKey(70);
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
});
|
||||
@ -50,17 +51,14 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||
|
||||
utils.pressKey(74);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<img src="../media/blue.png" id="jspsych-iat-stim">');
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 70}));
|
||||
|
||||
utils.pressKey(70);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
});
|
||||
|
||||
@ -75,17 +73,14 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||
|
||||
utils.pressKey(70);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src=\"../media/blue.png\" id=\"jspsych-iat-stim\">'));
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 74}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 74}));
|
||||
|
||||
utils.pressKey(74);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
|
||||
});
|
||||
@ -103,17 +98,14 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 70}));
|
||||
|
||||
utils.pressKey(70);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src=\"../media/blue.png\" id=\"jspsych-iat-stim\" class=\" responded\">'));
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||
|
||||
utils.pressKey(32);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
|
||||
});
|
||||
@ -131,17 +123,14 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 74}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 74}));
|
||||
|
||||
utils.pressKey(74);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src=\"../media/blue.png\" id=\"jspsych-iat-stim\" class=\" responded\">'));
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 70}));
|
||||
|
||||
utils.pressKey(70);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
|
||||
});
|
||||
@ -159,15 +148,14 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<p>Press j for:<br> <b>UNFRIENDLY</b>'));
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<p>Press f for:<br> <b>FRIENDLY</b>'));
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode:70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode:70}));
|
||||
|
||||
utils.pressKey(70);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
|
||||
});
|
||||
@ -188,19 +176,15 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().querySelector('#wrongImgContainer').style.visibility).toBe('hidden');
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode:74}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode:74}));
|
||||
|
||||
utils.pressKey(74);
|
||||
expect(jsPsych.getDisplayElement().querySelector('#wrongImgContainer').style.visibility).toBe('visible');
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 70}));
|
||||
|
||||
utils.pressKey(70);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
});
|
||||
|
||||
@ -215,7 +199,8 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src=\"../media/blue.png\" id=\"jspsych-iat-stim\">'));
|
||||
@ -241,12 +226,11 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 70}));
|
||||
|
||||
utils.pressKey(70);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src=\"../media/blue.png\" id=\"jspsych-iat-stim\" class=\" responded\">'));
|
||||
|
||||
jest.runAllTimers();
|
||||
@ -269,16 +253,15 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src="../media/blue.png" id=\"jspsych-iat-stim\">'));
|
||||
|
||||
jest.runTimersToTime(500);
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 73}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 73}));
|
||||
|
||||
utils.pressKey(73);
|
||||
expect(jsPsych.getDisplayElement().querySelector('#wrongImgContainer').style.visibility).toBe('visible');
|
||||
|
||||
jest.runTimersToTime(1100);
|
||||
@ -304,14 +287,13 @@ describe('iat-image plugin', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src="../media/blue.png" id=\"jspsych-iat-stim\">'));
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 73}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 73}));
|
||||
|
||||
utils.pressKey(73);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src=\"../media/blue.png\" id=\"jspsych-iat-stim\" class=\" responded\">'));
|
||||
|
||||
jest.runTimersToTime(1000);
|
||||
@ -320,9 +302,7 @@ describe('iat-image plugin', function(){
|
||||
|
||||
jest.runTimersToTime(1500);
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode: 69}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode: 69}));
|
||||
|
||||
utils.pressKey(69);
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe("");
|
||||
});
|
||||
});
|
||||
|
@ -22,7 +22,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<img src="../media/blue.png" id="jspsych-image-button-response-stimulus">');
|
||||
@ -36,7 +37,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<button class=\"jspsych-btn\">button-choice1</button>'));
|
||||
@ -52,7 +54,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<button class="jspsych-custom-button">buttonChoice</button>'));
|
||||
@ -66,7 +69,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src="../media/blue.png" id="jspsych-image-button-response-stimulus">'));
|
||||
@ -85,7 +89,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<button class=\"jspsych-btn\">button-choice</button></div></div><p>This is a prompt</p>');
|
||||
@ -100,7 +105,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-button-response-stimulus').style.visibility).toMatch("");
|
||||
@ -117,7 +123,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<img src="../media/blue.png" id="jspsych-image-button-response-stimulus">');
|
||||
@ -134,7 +141,8 @@ describe('image-button-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<img src="../media/blue.png" id="jspsych-image-button-response-stimulus">');
|
||||
|
@ -1,4 +1,5 @@
|
||||
const root = '../../';
|
||||
const utils = require('../testing-utils.js');
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
@ -20,10 +21,13 @@ describe('image-keyboard-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('<img src=\"../media/blue.png\" id=\"jspsych-image-keyboard-response-stimulus\">');
|
||||
|
||||
utils.pressKey(70);
|
||||
});
|
||||
|
||||
test('display clears after key press', function(){
|
||||
@ -34,13 +38,13 @@ describe('image-keyboard-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src="../media/blue.png" id="jspsych-image-keyboard-response-stimulus">'));
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode:70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode:70}));
|
||||
utils.pressKey(70);
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
});
|
||||
@ -54,10 +58,12 @@ describe('image-keyboard-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src="../media/blue.png" id="jspsych-image-keyboard-response-stimulus"><div id="foo">this is a prompt</div>'));
|
||||
utils.pressKey(70);
|
||||
});
|
||||
|
||||
test('should hide stimulus if stimulus-duration is set', function(){
|
||||
@ -69,12 +75,14 @@ describe('image-keyboard-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-keyboard-response-stimulus').style.visibility).toMatch("");
|
||||
jest.runTimersToTime(500);
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-keyboard-response-stimulus').style.visibility).toMatch("hidden");
|
||||
utils.pressKey(70);
|
||||
|
||||
});
|
||||
|
||||
@ -87,7 +95,8 @@ describe('image-keyboard-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src="../media/blue.png" id="jspsych-image-keyboard-response-stimulus">'));
|
||||
@ -104,13 +113,13 @@ describe('image-keyboard-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch(new RegExp('<img src="../media/blue.png" id="jspsych-image-keyboard-response-stimulus">'));
|
||||
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keydown', {keyCode:70}));
|
||||
document.querySelector('.jspsych-display-element').dispatchEvent(new KeyboardEvent('keyup', {keyCode:70}));
|
||||
utils.pressKey(70);
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||
});
|
||||
|
@ -14,19 +14,23 @@ describe('image-slider-response', function(){
|
||||
expect(typeof window.jsPsych.plugins['image-slider-response']).not.toBe('undefined');
|
||||
});
|
||||
|
||||
test('displays image stimulus', function(){
|
||||
test('displays image stimulus', function(done){
|
||||
var trial = {
|
||||
type: 'image-slider-response',
|
||||
stimulus: '../media/blue.png',
|
||||
labels: ['left', 'right'],
|
||||
button_label: 'button'
|
||||
button_label: 'button',
|
||||
on_load: function(){
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<div id="jspsych-image-slider-response-stimulus"><img src="../media/blue.png"></div>');
|
||||
utils.clickTarget(document.querySelector('#jspsych-image-slider-response-next'));
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<div id="jspsych-image-slider-response-stimulus"><img src="../media/blue.png"></div>');
|
||||
});
|
||||
|
||||
test('displays labels', function(){
|
||||
@ -38,11 +42,14 @@ describe('image-slider-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<span style=\"text-align: center; font-size: 80%;\">left</span>');
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<span style=\"text-align: center; font-size: 80%;\">right</span>');
|
||||
|
||||
utils.clickTarget(document.querySelector('#jspsych-image-slider-response-next'));
|
||||
})
|
||||
|
||||
test('displays button label', function(){
|
||||
@ -54,10 +61,13 @@ describe('image-slider-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<button id=\"jspsych-image-slider-response-next\" class=\"jspsych-btn\">button</button>');
|
||||
|
||||
utils.clickTarget(document.querySelector('#jspsych-image-slider-response-next'));
|
||||
});
|
||||
|
||||
test('should set min, max and step', function(){
|
||||
@ -72,15 +82,18 @@ describe('image-slider-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-slider-response-response').min).toBe('2');
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-slider-response-response').max).toBe('10');
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-image-slider-response-response').step).toBe('2');
|
||||
|
||||
utils.clickTarget(document.querySelector('#jspsych-image-slider-response-next'));
|
||||
});
|
||||
|
||||
test('should append to bottom on stimulus', function(){
|
||||
test('prompt should append to bottom of stimulus', function(){
|
||||
var trial = {
|
||||
type: 'image-slider-response',
|
||||
stimulus: '../media/blue.png',
|
||||
@ -90,10 +103,13 @@ describe('image-slider-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<p>This is a prompt</p>');
|
||||
|
||||
utils.clickTarget(document.querySelector('#jspsych-image-slider-response-next'));
|
||||
});
|
||||
|
||||
test('should hide stimulus if stimulus_duration is set', function(){
|
||||
@ -106,12 +122,14 @@ describe('image-slider-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
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(){
|
||||
@ -125,7 +143,8 @@ describe('image-slider-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<div id="jspsych-image-slider-response-stimulus"><img src="../media/blue.png"></div>');
|
||||
@ -143,7 +162,8 @@ describe('image-slider-response', function(){
|
||||
}
|
||||
|
||||
jsPsych.init({
|
||||
timeline: [trial]
|
||||
timeline: [trial],
|
||||
auto_preload: false
|
||||
});
|
||||
|
||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('<div id="jspsych-image-slider-response-stimulus"><img src="../media/blue.png"></div>');
|
||||
|
@ -26,8 +26,6 @@ describe('survey-multi-select plugin', function(){
|
||||
timeline: [trial]
|
||||
});
|
||||
|
||||
console.log(jsPsych.getDisplayElement().innerHTML);
|
||||
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-survey-multi-select-option-0-0 input').value).toBe('Hello "boo"');
|
||||
expect(jsPsych.getDisplayElement().querySelector('#jspsych-survey-multi-select-option-0-1 input').value).toBe("yes, 'bar'");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user