new tests for addNodeToEndOfTimeline

This commit is contained in:
Becky Gilbert 2020-10-15 17:33:33 -07:00
parent a05fc287c0
commit 9d9612888b

View File

@ -347,3 +347,63 @@ describe('endCurrentTimeline', function(){
utils.pressKey(32);
})
});
describe('add node to end of timeline', function(){
test('adds node to end of timeline, without callback', function() {
var new_trial = {
type: 'html-keyboard-response',
stimulus: 'bar'
};
var new_timeline = {
timeline: [new_trial]
};
var timeline = [
{
type: 'html-keyboard-response',
stimulus: 'foo',
on_start: function() {
jsPsych.addNodeToEndOfTimeline(new_timeline);
}
}
];
jsPsych.init({
timeline: timeline
});
expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo');
utils.pressKey(32);
expect(jsPsych.getDisplayElement().innerHTML).toMatch('bar');
utils.pressKey(32);
});
test('adds node to end of timeline, with callback', function() {
var t = {
type: 'html-keyboard-response',
stimulus: 'foo',
on_finish: function(){
jsPsych.pauseExperiment();
jsPsych.addNodeToEndOfTimeline({
timeline: [{
type: 'html-keyboard-response',
stimulus: 'bar'
}]
}, jsPsych.resumeExperiment)
}
};
jsPsych.init({
timeline: [t]
});
expect(jsPsych.getDisplayElement().innerHTML).toMatch('foo');
utils.pressKey(32);
expect(jsPsych.getDisplayElement().innerHTML).toMatch('bar');
utils.pressKey(32);
});
});