Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('validates on blur if validateOnBlur is true', async () => {
const schema = yup.object().shape({
email: yup.string().email(),
});
const { component, getByPlaceholderText } = await render(App, {
props: { schema, validateOnChange: false, validateOnBlur: true },
});
const emailInput = getByPlaceholderText('Email');
await fireEvent.change(emailInput, {
target: { value: 'invalid value' },
});
await fireEvent.blur(emailInput);
await wait();
expect(component.form.$$.ctx.$errors).toEqual({
email: 'email must be a valid email',
});
});
}),
});
const {
container,
component,
getByPlaceholderText,
getByText,
} = await render(App, {
props: { schema },
});
const emailInput = getByPlaceholderText('Email');
await fireEvent.change(emailInput, {
target: { value: 'invalid value' },
});
await fireEvent.blur(emailInput);
await wait(() => {
expect(getByText('user.email must be a valid email')).toBeInTheDocument();
});
expect(component.form.$$.ctx.$errors).toEqual({
user: { email: 'user.email must be a valid email' },
});
expect(container.firstChild).toMatchSnapshot();
});
click: async () => {
const el = await elem();
await fireEvent.mouseDown(el);
if (elementIsFocusable(el)) {
if (document.activeElement != el) {
if (document.activeElement) {
fireEvent.blur(document.activeElement);
}
if (!el.disabled) {
el.focus();
await fireEvent.focus(el);
}
}
}
await fireEvent.mouseUp(el);
await fireEvent.click(el);
if (isCheckable(el)) {
handleCheckableInput(el as HTMLInputElement);
}