Skip to content

fix: allow type to receive a number value #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions projects/testing-library/src/lib/user-events/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function createType(fireEvent: FireFunction & FireObject) {
};
}

return async function type(element: HTMLElement, value: string, options?: TypeOptions) {
return async function type(element: HTMLElement, value: string | number, options?: TypeOptions) {
const { allAtOnce = false, delay = 0 } = options || {};
const initialValue = (element as HTMLInputElement).value;

Expand All @@ -46,9 +46,10 @@ export function createType(fireEvent: FireFunction & FireObject) {
return;
}

const text = value.toString();
let actuallyTyped = '';
for (let index = 0; index < value.length; index++) {
const char = value[index];
for (let index = 0; index < text.length; index++) {
const char = text[index];
const key = char;
const keyCode = char.charCodeAt(0);

Expand Down
2 changes: 1 addition & 1 deletion src/app/examples/03-forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('is possible to fill in a form and verify error messages (with the help of
expect(component.queryByText('color is required')).not.toBeInTheDocument();

expect(scoreControl).toBeInvalid();
component.type(scoreControl, '7');
component.type(scoreControl, 7);
expect(scoreControl).toBeValid();

expect(errors).not.toBeInTheDocument();
Expand Down
4 changes: 2 additions & 2 deletions src/app/examples/04-forms-with-material.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ test('is possible to fill in a form and verify error messages (with the help of
expect(errors).toContainElement(component.queryByText('color is required'));

component.type(nameControl, 'Tim');
component.type(scoreControl, '12');
component.type(scoreControl, 12);
component.selectOptions(colorControl, 'Green');

expect(component.queryByText('name is required')).not.toBeInTheDocument();
expect(component.queryByText('score must be lesser than 10')).toBeInTheDocument();
expect(component.queryByText('color is required')).not.toBeInTheDocument();

expect(scoreControl).toBeInvalid();
component.type(scoreControl, '7');
component.type(scoreControl, 7);
expect(scoreControl).toBeValid();

expect(errors).not.toBeInTheDocument();
Expand Down