Skip to content

Commit

Permalink
fix(tests): enhance input handling in typeTest function for text elem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
BGBRWR committed Nov 27, 2024
1 parent 90c2b27 commit 25a510a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions projects/ngx-mask-lib/src/test/utils/test-functions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,19 @@ export function typeTest(inputValue: string, fixture: any): string {

{
for (const element of inputArray) {
inputElement.dispatchEvent(new Event('keydown'), { key: element });
inputElement.value += element;
inputElement.dispatchEvent(new KeyboardEvent('keydown'), { key: element });
if (inputElement.type === 'text') {
const selectionStart = inputElement.selectionStart || 0;
const selectionEnd = inputElement.selectionEnd || 0;
inputElement.value =
inputElement.value.slice(0, selectionStart) +
element +
inputElement.value.slice(selectionEnd);

inputElement.selectionStart = selectionStart + 1;
} else {
inputElement.value += element;
}
inputElement.dispatchEvent(new Event('input'));
inputElement.dispatchEvent(new Event('ngModelChange'));
}
Expand Down

0 comments on commit 25a510a

Please sign in to comment.