UNPKG

siesta-lite

Version:

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

63 lines (47 loc) 1.98 kB
describe('disabled / readonly INPUTs', function (t) { t.it('Should simulate key events even if input is readonly', function (t) { document.body.innerHTML = '<input type="text" id="foo" readonly="readonly"/>'; t.willFireNTimes('#foo', 'keydown', 1) t.willFireNTimes('#foo', 'keypress', 1) // sporadically not simulated for some reason in native on Linux t.willFireNTimes('#foo', 'keyup', t.simulator.type == 'native' ? '<=1' : 1) var input = document.getElementById('foo') t.chain( { type : 'b', target : '#foo' }, function () { t.expect(input.value).toBe(''); } ) }); t.it('Should NOT simulate key events if input is disabled', function (t) { document.body.innerHTML = '<input type="text" id="baz" disabled="disabled"/>'; t.wontFire('#baz', 'keydown', 1) t.wontFire('#baz', 'keypress', 1) t.wontFire('#baz', 'keyup', 1) t.chain( { type : 'b', target : '#baz' }, function () { t.expect(document.getElementById('baz').value).toBe(''); } ) }); t.it('Should respect readonly when text is selected', function (t) { document.body.innerHTML = '<input type="text" id="foo" value="foo" readonly="readonly"/>'; t.selectText('#foo'); t.chain( { type : 'b', target : '#foo' }, function () { t.expect(document.getElementById('foo').value).toBe('foo'); } ) }); t.it('Should respect readonly when deleting using DELETE key', function (t) { document.body.innerHTML = '<input type="text" id="foo" value="foo" readonly="readonly"/>'; t.chain( { type : '[DELETE]', target : '#foo' }, function () { t.expect(document.getElementById('foo').value).toBe('foo'); } ) }); });