forked from FrontendMasters/testing-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit and integration on the frontend 👍
- Loading branch information
Kent C. Dodds
committed
Mar 9, 2017
1 parent
40d2828
commit e1f4713
Showing
18 changed files
with
465 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from 'react' | ||
import {mount} from 'enzyme' | ||
import {Component as Login} from '../login' | ||
|
||
test('renders login form by default', () => { | ||
const wrapper = render() | ||
expect(isSubmitButtonDisabled(wrapper)).toBe(false) | ||
}) | ||
|
||
test('disabled button when inProgress', () => { | ||
const wrapper = render({inProgress: true}) | ||
expect(isSubmitButtonDisabled(wrapper)).toBe(true) | ||
}) | ||
|
||
test('shows list of errors when there are errors', () => { | ||
const wrapper = render({ | ||
errors: { | ||
'some-error': 'there was some error', | ||
'some-other-error': 'there was some other error', | ||
}, | ||
}) | ||
expect(getErrors(wrapper)).toEqual([ | ||
'some-error there was some error', | ||
'some-other-error there was some other error', | ||
]) | ||
}) | ||
|
||
function render(props = {}) { | ||
const propsToUse = { | ||
onSubmit() {}, | ||
onUnload() {}, | ||
inProgress: false, | ||
errors: {}, | ||
...props, | ||
} | ||
return mount(<Login {...propsToUse} />) | ||
} | ||
|
||
function isSubmitButtonDisabled(wrapper) { | ||
const button = getSubmitButton(wrapper).getNode() | ||
return button.disabled | ||
} | ||
|
||
function getSubmitButton(wrapper) { | ||
return wrapper.find('button[type="submit"]') | ||
} | ||
|
||
function getErrors(wrapper) { | ||
return Array.from(wrapper.find('.error-messages li').getNodes()) | ||
.map(n => n.textContent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.