mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
add tests
This commit is contained in:
parent
7e288d4481
commit
d465c20b05
@ -43,6 +43,25 @@ describe('standard use of function as parameter', function(){
|
|||||||
expect(jsPsych.getDisplayElement().innerHTML).toMatch('bar');
|
expect(jsPsych.getDisplayElement().innerHTML).toMatch('bar');
|
||||||
utils.pressKey('a');
|
utils.pressKey('a');
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('parameters can be protected from early evaluation using jsPsych.plugins.parameterType.FUNCTION', function(){
|
||||||
|
require(root + 'plugins/jspsych-cloze.js');
|
||||||
|
|
||||||
|
var mock = jest.fn();
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'cloze',
|
||||||
|
text: '%foo%',
|
||||||
|
check_answers: true,
|
||||||
|
mistake_fn: mock
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({timeline: [trial]});
|
||||||
|
|
||||||
|
expect(mock).not.toHaveBeenCalled();
|
||||||
|
utils.clickTarget(document.querySelector('#finish_cloze_button'));
|
||||||
|
expect(mock).toHaveBeenCalledTimes(1);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('data as function', function(){
|
describe('data as function', function(){
|
||||||
@ -84,7 +103,6 @@ describe('data as function', function(){
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('nested parameters as functions', function(){
|
describe('nested parameters as functions', function(){
|
||||||
|
|
||||||
|
|
||||||
test('entire parameter can be a function', function(){
|
test('entire parameter can be a function', function(){
|
||||||
|
|
||||||
@ -118,9 +136,31 @@ describe('nested parameters as functions', function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(document.querySelector('#jspsych-survey-text-0 p.jspsych-survey-text').innerHTML).toBe('foo');
|
expect(document.querySelector('#jspsych-survey-text-0 p.jspsych-survey-text').innerHTML).toBe('foo');
|
||||||
|
expect(document.querySelector('#jspsych-survey-text-1 p.jspsych-survey-text').innerHTML).toBe('bar');
|
||||||
utils.clickTarget(document.querySelector('#jspsych-survey-text-next'));
|
utils.clickTarget(document.querySelector('#jspsych-survey-text-next'));
|
||||||
|
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||||
|
})
|
||||||
|
|
||||||
|
test('multiple nested parameters can be functions', function(){
|
||||||
|
require(root + 'plugins/jspsych-survey-multi-choice.js');
|
||||||
|
|
||||||
|
var trial = {
|
||||||
|
type: 'survey-multi-choice',
|
||||||
|
questions: [
|
||||||
|
{prompt: function(){ return "foo"; }, options: function() { return ['buzz','fizz']; }},
|
||||||
|
{prompt: "bar", options: function() { return ['one','two']; }}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
jsPsych.init({
|
||||||
|
timeline: [trial]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(document.querySelector('#jspsych-survey-multi-choice-0').innerHTML).toMatch('foo');
|
||||||
|
expect(document.querySelector('#jspsych-survey-multi-choice-0').innerHTML).toMatch('buzz');
|
||||||
|
expect(document.querySelector('#jspsych-survey-multi-choice-1').innerHTML).toMatch('bar');
|
||||||
|
expect(document.querySelector('#jspsych-survey-multi-choice-1').innerHTML).toMatch('one');
|
||||||
|
utils.clickTarget(document.querySelector('#jspsych-survey-multi-choice-next'));
|
||||||
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user