UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

47 lines (35 loc) 1.43 kB
describe('event.key', function (t) { if (bowser.msie) return; document.body.innerHTML = '<input type="text" id="foo"/>'; var input = document.getElementById('foo') t.it('Should provide "key" property for special key', function (t) { var assertKeyValue = function (e) { t.expect(e.key).toBe('Escape') } input.addEventListener('keydown', assertKeyValue); input.addEventListener('keyup', assertKeyValue); t.chain( { type : '[ESCAPE]', target : '#foo' }, function () { input.removeEventListener('keydown', assertKeyValue); input.removeEventListener('keyup', assertKeyValue); } ) }); t.it('Should provide "key" property for regular key', function (t) { var assertKeyValue = function (e) { t.expect(e.key).toBe('a') } input.addEventListener('keydown', assertKeyValue); input.addEventListener('keypress', assertKeyValue); input.addEventListener('keyup', assertKeyValue); t.chain( { type : 'a', target : '#foo' }, function () { input.removeEventListener('keydown', assertKeyValue); input.removeEventListener('keypress', assertKeyValue); input.removeEventListener('keyup', assertKeyValue); } ) }); });