I have a jQuery plugin that limits character entry with an input element. This plugin (similar to numeric) hooks into keydown and keyup to allow certain characters prevent the event under certain conditions:
jqueryInputElement.on('keydown', function(event){
if (wrongThingEntered(event))
event.stopPropagation();
event.preventDefault();
});
wrongThingEntered
does funky things with the character code and modifier keys in the event and the current inputted value (missing from this example). For this reason I need to simulate character entry from Karma for different devices so that I can test the value after keydowns and keyups etc.
I understand that I can simulate using jQuery trigger or similar, but after going down the rabbit-hole of what keys map to what character codes on different devices, I came to the conclusion that triggering these low-level events did not solve my problem, and the tests weren't really testing anything.
I'm really after something like this:
describe 'hello world', ->
element = undefined
beforeEach ->
element = $('<input>')
element.customPlugin()
element.focus()
afterEach ->
element.remove()
describe 'keyboard events work', ->
it 'receives some input', ->
karma.user.presses '4' # not sure about this part
expect element.val()
.toBe '4'
it 'respects paste commands', ->
karma.system.pasteBuffer = "some text to paste" # and also this part
karma.user.pastes() # ... and this part
expect element.val()
.toBe "some text to paste"
Is this possible with Karma (in my case running phantomJS)?