Jasmine example
A simple example of Jasmine tests using JSFiddle
HTML
<script src="http://searls.github.io/jasmine-all/jasmine-all-min.js"></script>
<input id="first"></input>
<input id="second"></input>
JavaScript
function simulateTab() {
var TAB_KEY = 9;
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod]("keydown", true, true, window, 0, 0, 0, 0, 0, TAB_KEY);
document.dispatchEvent(keyboardEvent);
}
describe('input tabbing test', function() {
beforeEach(function() {
document.getElementById('first').focus();
});
it('input with id "first" should be focussed', function() {
expect(document.activeElement.getAttribute('id')).toBe('first');
});
it('input with id "second" should be focussed after tabbing', function() {
simulateTab();
expect(document.activeElement.getAttribute('id')).toBe('second');
});
});