mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00
add tests for conditional_function
This commit is contained in:
parent
e09f4749ef
commit
71027fc07d
@ -117,4 +117,117 @@ describe('loop function', function(){
|
|||||||
expect(jsPsych.data.get().count()).toBe(3);
|
expect(jsPsych.data.get().count()).toBe(3);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('conditional function', function(){
|
||||||
|
|
||||||
|
test('skips the timeline when returns false', function(){
|
||||||
|
|
||||||
|
var conditional = {
|
||||||
|
timeline: [{
|
||||||
|
type: 'text',
|
||||||
|
text: 'foo'
|
||||||
|
}],
|
||||||
|
conditional_function: function(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'text',
|
||||||
|
text: 'bar'
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [conditional, trial]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(jsPsych.getDisplayElement().innerHTML).toBe('bar');
|
||||||
|
|
||||||
|
// clear
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('completes the timeline when returns true', function(){
|
||||||
|
var conditional = {
|
||||||
|
timeline: [{
|
||||||
|
type: 'text',
|
||||||
|
text: 'foo'
|
||||||
|
}],
|
||||||
|
conditional_function: function(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'text',
|
||||||
|
text: 'bar'
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [conditional, trial]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(jsPsych.getDisplayElement().innerHTML).toBe('foo');
|
||||||
|
|
||||||
|
// next
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
|
|
||||||
|
expect(jsPsych.getDisplayElement().innerHTML).toBe('bar');
|
||||||
|
|
||||||
|
// clear
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('executes on every loop of the timeline', function(){
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
var conditional_count = 0;
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
timeline: [{
|
||||||
|
type: 'text',
|
||||||
|
text: 'foo'
|
||||||
|
}],
|
||||||
|
loop_function: function(){
|
||||||
|
if(count < 1){
|
||||||
|
count++;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
conditional_function: function(){
|
||||||
|
conditional_count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [trial]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(conditional_count).toBe(1);
|
||||||
|
|
||||||
|
// first trial
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
|
|
||||||
|
expect(conditional_count).toBe(2);
|
||||||
|
|
||||||
|
// second trial
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
|
||||||
|
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
|
||||||
|
|
||||||
|
expect(conditional_count).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('endCurrentTimeline', function(){
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user