allows object parameters to have nested timelineVariables

This commit is contained in:
Josh de Leeuw 2017-07-21 22:11:43 -04:00
parent 12dcd30ad9
commit 15535820e0

View File

@ -81,7 +81,7 @@ describe('The data parameter', function(){
var trial = {
timeline: [
{type: 'html-keyboard-response',
{type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus')}
],
timeline_variables: vars,
@ -104,6 +104,58 @@ describe('The data parameter', function(){
})).then(function(data) { expect(data).toBe(2) });
});
test('should work as timeline variable at root level', function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-html-keyboard-response.js');
var trial = {
timeline: [
{type: 'html-keyboard-response', stimulus: 'foo', data: jsPsych.timelineVariable('d')}
],
timeline_variables: [
{d: {added: true}},
{d: {added: false}}
]
}
jsPsych.init({
timeline: [trial]
});
utils.pressKey(32); // trial 1
utils.pressKey(32); // trial 2
expect(jsPsych.data.get().filter({added: true}).count()).toBe(1);
expect(jsPsych.data.get().filter({added: false}).count()).toBe(1);
});
test('should work as timeline variable at nested level', function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-html-keyboard-response.js');
var trial = {
timeline: [
{type: 'html-keyboard-response', stimulus: 'foo', data: {added: jsPsych.timelineVariable('added')}}
],
timeline_variables: [
{added: true},
{added: false}
]
}
jsPsych.init({
timeline: [trial]
});
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);
});
test.skip('should record data to all nested trials with timeline variables even when nested trials have own data', function(){
require(root + 'jspsych.js');