Created
September 2, 2019 11:46
-
-
Save alonbardavid/6bbf3fd176f2de094c7a90ccb9bb4483 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test('when maxLength is 1, input should reject any keypress',()=>{ | |
//assuming we have a div in our test environment with the id #test-app | |
const onChangeCalls = []; | |
myComponent("#test-app","my-label","A",{maxLength:1},(value)=>calls.push(value)); | |
const input = document.querySelector("#test-app input"); | |
//this test is a simplified version, to really simulate an input event, you'll need to | |
//change the target value, call more events and react like the browser. | |
input.dispatchEvent(new Event('keypress',{bubbles:true,cancelable:true,key:"B"})) | |
expect(calls.length).toEqual(0); | |
expect(input.value).toEqual("A"); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment