Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- test('login form submits', async () => {
- const fakeUser = { username: 'jackiechan', password: 'hiya! 🥋' };
- const handleLogin = {
- emit: jest.fn(),
- };
- const { container, getByLabelText, getByText } = await createComponent(
- {
- component: LoginFormComponent,
- parameters: {
- handleLogin: handleLogin as any,
- },
- },
- {
- declarations: [LoginFormComponent],
- imports: [ReactiveFormsModule],
- },
- );
- const usernameNode = getByLabelText(/username/i) as HTMLInputElement;
- const passwordNode = getByLabelText(/password/i) as HTMLInputElement;
- const submitButtonNode = getByText(/submit/i);
- const formNode = container.querySelector('form');
- usernameNode.value = fakeUser.username;
- fireEvent.input(usernameNode);
- passwordNode.value = fakeUser.password;
- fireEvent.input(passwordNode);
- fireEvent.submit(formNode);
- expect(handleLogin.emit).toHaveBeenCalledTimes(1);
- expect(handleLogin.emit).toHaveBeenCalledWith(fakeUser);
- expect(submitButtonNode.type).toBe('submit');
- });
Add Comment
Please, Sign In to add comment