mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
added tests for #883
This commit is contained in:
parent
b6a28b0433
commit
5881c4455e
@ -277,4 +277,149 @@ describe('timeline variables are correctly evaluated', function(){
|
|||||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('bar');
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch('bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('when used in a conditional_function', function(){
|
||||||
|
var tvs = [
|
||||||
|
{x: 'foo'}
|
||||||
|
]
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'html-keyboard-response',
|
||||||
|
stimulus: 'hello world'
|
||||||
|
}
|
||||||
|
|
||||||
|
var x = null;
|
||||||
|
|
||||||
|
var p = {
|
||||||
|
timeline: [trial],
|
||||||
|
timeline_variables: tvs,
|
||||||
|
conditional_function: function(){
|
||||||
|
x = jsPsych.timelineVariable('x');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [p]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
utils.pressKey(32);
|
||||||
|
expect(x).toBe('foo');
|
||||||
|
})
|
||||||
|
|
||||||
|
test('when used in a loop_function', function(){
|
||||||
|
var tvs = [
|
||||||
|
{x: 'foo'}
|
||||||
|
]
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'html-keyboard-response',
|
||||||
|
stimulus: 'hello world'
|
||||||
|
}
|
||||||
|
|
||||||
|
var x = null;
|
||||||
|
|
||||||
|
var p = {
|
||||||
|
timeline: [trial],
|
||||||
|
timeline_variables: tvs,
|
||||||
|
loop_function: function(){
|
||||||
|
x = jsPsych.timelineVariable('x');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [p]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
utils.pressKey(32);
|
||||||
|
expect(x).toBe('foo');
|
||||||
|
})
|
||||||
|
|
||||||
|
test('when used in on_finish', function(){
|
||||||
|
var tvs = [
|
||||||
|
{x: 'foo'}
|
||||||
|
]
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'html-keyboard-response',
|
||||||
|
stimulus: 'hello world',
|
||||||
|
on_finish: function(data){
|
||||||
|
data.x = jsPsych.timelineVariable('x');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var t = {
|
||||||
|
timeline: [trial],
|
||||||
|
timeline_variables: tvs
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [t]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
utils.pressKey(32);
|
||||||
|
expect(jsPsych.data.get().values()[0].x).toBe('foo');
|
||||||
|
})
|
||||||
|
|
||||||
|
test('when used in on_start', function(){
|
||||||
|
var tvs = [
|
||||||
|
{x: 'foo'}
|
||||||
|
]
|
||||||
|
|
||||||
|
var x = null;
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'html-keyboard-response',
|
||||||
|
stimulus: 'hello world',
|
||||||
|
on_start: function(){
|
||||||
|
x = jsPsych.timelineVariable('x');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var t = {
|
||||||
|
timeline: [trial],
|
||||||
|
timeline_variables: tvs
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [t]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
utils.pressKey(32);
|
||||||
|
expect(x).toBe('foo');
|
||||||
|
})
|
||||||
|
|
||||||
|
test('when used in on_load', function(){
|
||||||
|
var tvs = [
|
||||||
|
{x: 'foo'}
|
||||||
|
]
|
||||||
|
|
||||||
|
var x = null;
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'html-keyboard-response',
|
||||||
|
stimulus: 'hello world',
|
||||||
|
on_load: function(){
|
||||||
|
x = jsPsych.timelineVariable('x');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var t = {
|
||||||
|
timeline: [trial],
|
||||||
|
timeline_variables: tvs
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [t]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
utils.pressKey(32);
|
||||||
|
expect(x).toBe('foo');
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user