spec/game_spec.js
function simulateKeyboardEvent(type, key) {
    var codes = {
        left: 37,
        up: 38,
        right: 39,
        down: 40,
        w: 87,
        a: 65,
        s: 83,
        d: 68,
        enter: 13,
        escape: 27,
        space: 32,
        control: 17,
        z: 90,
        x: 88
    };

    var event = new KeyboardEvent(type); // allowed: keydown, keyup

    Object.defineProperty(event, 'keyCode', {
        get: function () {
            return codes[key];
        }
    });

    document.dispatchEvent(event);
}
function simulateKeyboardEvent(type, key) {
    var codes = {
        left: 37,
        up: 38,
        right: 39,
        down: 40,
        w: 87,
        a: 65,
        s: 83,
        d: 68,
        enter: 13,
        escape: 27,
        space: 32,
        control: 17,
        z: 90,
        x: 88
    };

    var event = new KeyboardEvent(type); // allowed: keydown, keyup

    Object.defineProperty(event, 'keyCode', {
        get: function () {
            return codes[key];
        }
    });

    document.dispatchEvent(event);
}
/* HELPER METHODS