-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLoginForm.test.js
More file actions
41 lines (33 loc) · 1.19 KB
/
LoginForm.test.js
File metadata and controls
41 lines (33 loc) · 1.19 KB
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
import LoginForm from './LoginForm';
describe('<LoginForm />', () => {
// Page object definition for this component,
// the main reason of this example
function Page(component) {
this.formField = (name) => component.find(`[name="${name}"]`);
this.submitBtn = () => component.find('button[type="submit"]');
this.$el = component;
}
// Setup function for component
// Accepts props for compient as argument
// Returns compound object that we can destructurize
function createComponent(props) {
const onSubmit = jest.fn();
const view = new LoginForm({...props, onSubmit}).render();
const page = new Page(view.$el);
return {page, onSubmit};
}
it('should render default email', () => {
const {page} = createComponent({email: 'test@email.com'});
expect(page.formField('email').prop('value')).toEqual('test@email.com');
});
it('should submit form', () => {
const {page, onSubmit} = createComponent();
page.formField('email').val('test@email.com');
page.formField('password').val('letmein');
page.submitBtn().trigger('click');
expect(onSubmit).toBeCalledWith({
email: 'test@email.com',
password: 'letmein'
});
});
})