Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.string()
.required()
.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();
});
it('does not validate on change if validateOnChange is false', async () => {
const schema = yup.object().shape({
email: yup.string().email(),
});
const { component, getByPlaceholderText } = await render(App, {
props: { schema, validateOnChange: false },
});
const emailInput = getByPlaceholderText('Email');
await fireEvent.change(emailInput, {
target: { value: 'invalid value' },
});
await wait();
expect(component.form.$$.ctx.$errors).toEqual({});
});
expect(component.form.$$.ctx.$errors).toMatchSnapshot();
expect(component.form.$$.ctx.$touched).toMatchSnapshot();
done();
}
),
},
});
const emailInput = getByPlaceholderText('Email');
await fireEvent.change(emailInput, {
target: { value: 'test@user.com' },
});
const languageSelect = container.querySelector('select');
await fireEvent.change(languageSelect, {
target: { value: 'svelte' },
});
let osChoice = getByText('macOS');
await fireEvent.click(osChoice);
osChoice = getByText('Windows');
await fireEvent.click(osChoice);
const signInButton = getByText('Sign in');
expect(component.form.$$.ctx.$isSubmitting).toBe(false);
expect(signInButton).not.toHaveAttribute('disabled');
await fireEvent.click(signInButton);
});
const handleCheckableInput = async (input: HTMLInputElement) => {
input.checked = !input.checked;
await fireEvent.input(input);
await fireEvent.change(input);
}
enterValue: async (value: string) => {
const el = (await elem()) as HTMLInputElement;
const { name, type } = el;
await fireEvent.change(el, {
target: { name, type, value }
});
},
attr: async (name: string) => {