flesh out testing suite framework for plugins #351

This commit is contained in:
Josh de Leeuw 2017-03-19 21:44:41 -04:00
parent a3a2df6ce0
commit 210dc8b834
4 changed files with 60 additions and 30 deletions

8
tests/loads.test.js Normal file
View File

@ -0,0 +1,8 @@
const root = '../';
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-single-stim.js');
test('jsPsych should be in the window object', function(){
expect(typeof window.jsPsych).not.toBe('undefined');
});

BIN
tests/media/blue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
tests/media/orange.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -1,34 +1,56 @@
const root = '../../';
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-single-stim.js');
describe('single-stim plugin', function(){
test('jsPsych should be in the window object', function(){
expect(typeof window.jsPsych).not.toBe('undefined');
beforeEach(function(){
require(root + 'jspsych.js');
require(root + 'plugins/jspsych-single-stim.js');
});
test('loads correctly', function(){
expect(typeof window.jsPsych.plugins['single-stim']).not.toBe('undefined');
});
test('displays image by default', function(){
var trial = {
type: 'single-stim',
stimulus: '../media/blue.png'
}
jsPsych.init({
timeline: [trial]
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('<img src="../media/blue.png" id="jspsych-single-stim-stimulus">');
});
test('displays html when is_html is true', function(){
var trial = {
type: 'single-stim',
stimulus: '<p>hello</p>',
is_html: true
}
jsPsych.init({
timeline: [trial]
});
expect(jsPsych.getDisplayElement().innerHTML).toBe('<div id="jspsych-single-stim-stimulus"><p>hello</p></div>');
});
test('display should clear after key press', function(){
var trial = {
type: 'single-stim',
stimulus: '<p>hello</p>'
}
jsPsych.init({
timeline: [trial]
});
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
expect(jsPsych.getDisplayElement().innerHTML).toBe('');
});
});
test('the single-stim plugin should be loaded', function(){
expect(typeof window.jsPsych.plugins['single-stim']).not.toBe('undefined');
})
var trial = {
type: 'single-stim',
stimulus: '<p>Hello</p>',
is_html: true
}
jsPsych.init({
timeline: [trial]
});
test('HMTL stimulus should display', function(){
var display_element = jsPsych.getDisplayElement();
expect(display_element.innerHTML).toBe('<div id="jspsych-single-stim-stimulus"><p>Hello</p></div>');
});
test('Display should clear after keypress', function(){
document.dispatchEvent(new KeyboardEvent('keydown', {keyCode: 32}));
document.dispatchEvent(new KeyboardEvent('keyup', {keyCode: 32}));
var display_element = jsPsych.getDisplayElement();
expect(display_element.innerHTML).toBe('');
})