This repository has been archived by the owner on Aug 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
SignUpForm.test.js
61 lines (48 loc) · 1.89 KB
/
SignUpForm.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from "react";
import { mount } from "enzyme";
import { setInputFieldValue } from "commons/utils/test-util";
import SignUpFormUnconnected from "./SignUpForm";
describe("SignUpForm", () => {
const onSubmit = jest.fn(({ name, email, password }) => {
Promise.resolve();
});
let component;
beforeEach(() => {
component = mount(<SignUpFormUnconnected onSubmit={onSubmit} />);
});
it("does not trigger submit when name is not provided", () => {
setInputFieldValue(component, "name", "");
setInputFieldValue(component, "email", "test@example.com");
setInputFieldValue(component, "password", "password");
component.find("button[type='submit']").simulate("submit");
expect(onSubmit).not.toBeCalled();
});
it("does not trigger submit when email is not provided", () => {
setInputFieldValue(component, "name", "test");
setInputFieldValue(component, "email", "");
setInputFieldValue(component, "password", "password");
component.find("button[type='submit']").simulate("submit");
expect(onSubmit).not.toBeCalled();
});
it("does not trigger submit when password is not provided", () => {
setInputFieldValue(component, "name", "test");
setInputFieldValue(component, "email", "test@example.com");
setInputFieldValue(component, "password", "");
component.find("button[type='submit']").simulate("submit");
expect(onSubmit).not.toBeCalled();
});
it("signs up users when name, email and password are provided", () => {
setInputFieldValue(component, "name", "test");
setInputFieldValue(component, "email", "test@example.com");
setInputFieldValue(component, "password", "password");
component.find("button[type='submit']").simulate("submit");
expect(onSubmit).toBeCalledWith(
{
name: "test",
email: "test@example.com",
password: "password"
},
expect.any(Object)
);
});
});