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.
- Loading branch information
Kent C. Dodds
committed
Apr 16, 2018
1 parent
6259787
commit 5d7050b
Showing
19 changed files
with
431 additions
and
38 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
148 changes: 148 additions & 0 deletions
148
client/src/components/__tests__/__snapshots__/login.step-4.js.snap
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,148 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`snapshot 1`] = ` | ||
.css-0, | ||
[data-css-0] { | ||
display: -webkit-box; | ||
display: -moz-box; | ||
display: -ms-flexbox; | ||
display: -webkit-flex; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
width: 100%; | ||
min-width: 200px; | ||
max-width: 400px; | ||
margin-left: -116px; | ||
-webkit-box-orient: vertical; | ||
-webkit-box-direction: normal; | ||
-webkit-flex-direction: column; | ||
-webkit-box-align: center; | ||
-webkit-align-items: center; | ||
} | ||
.css-1, | ||
[data-css-1] { | ||
display: grid; | ||
grid-template-columns: 100px 1fr; | ||
grid-gap: 16px; | ||
font-size: 18px; | ||
align-items: center; | ||
margin-top: 30px; | ||
margin-bottom: 30px; | ||
width: 100%; | ||
-ms-grid-template-columns: 100px 1fr; | ||
-ms-grid-gap: 16px; | ||
-webkit-box-align: center; | ||
-webkit-align-items: center; | ||
} | ||
.css-2, | ||
[data-css-2] { | ||
background: white; | ||
height: 50px; | ||
border: none; | ||
border-radius: 10px; | ||
box-shadow: var(--shadow); | ||
border-bottom: 5px; | ||
width: 100%; | ||
min-width: 150px; | ||
display: block; | ||
padding-left: 10px; | ||
} | ||
.css-2::-webkit-input-placeholder, | ||
[data-css-2]::-webkit-input-placeholder { | ||
opacity: 0.5; | ||
} | ||
.css-2::-moz-placeholder, | ||
[data-css-2]::-moz-placeholder { | ||
opacity: 0.5; | ||
} | ||
.css-2::-ms-input-placeholder, | ||
[data-css-2]::-ms-input-placeholder { | ||
opacity: 0.5; | ||
} | ||
.css-2::placeholder, | ||
[data-css-2]::placeholder { | ||
opacity: 0.5; | ||
} | ||
.css-7, | ||
[data-css-7] { | ||
font-size: 13px; | ||
font-family: Raleway,sans-serif; | ||
background: var(--green); | ||
padding: 10px 20px; | ||
display: block; | ||
margin-left: auto; | ||
color: white; | ||
border: none; | ||
border-radius: 10px; | ||
box-shadow: var(--shadow); | ||
cursor: pointer; | ||
transition: 0.5s; | ||
-webkit-transition: 0.5s; | ||
-moz-transition: 0.5s; | ||
} | ||
.css-7:hover, | ||
[data-css-7]:hover { | ||
box-shadow: var(--shadowHover); | ||
} | ||
@media only screen and (max-width: 819px) { | ||
.css-0, | ||
[data-css-0] { | ||
margin-left: 0; | ||
width: 90%; | ||
} | ||
} | ||
<div> | ||
<div | ||
style="display: flex;" | ||
> | ||
<form | ||
class="css-0" | ||
> | ||
<div | ||
class="css-1" | ||
> | ||
<label | ||
for="username-input" | ||
> | ||
Username | ||
</label> | ||
<input | ||
class="css-2" | ||
id="username-input" | ||
name="username" | ||
placeholder="Username..." | ||
/> | ||
<label | ||
id="password-input" | ||
> | ||
Password | ||
</label> | ||
<input | ||
aria-labelledby="password-input" | ||
class="css-2" | ||
name="password" | ||
placeholder="Password..." | ||
type="password" | ||
/> | ||
</div> | ||
<button | ||
class="css-7" | ||
type="submit" | ||
> | ||
Submit | ||
</button> | ||
</form> | ||
</div> | ||
</div> | ||
`; |
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,28 @@ | ||
import React from 'react' | ||
import {generate, renderIntoDocument, cleanup} from 'til-client-test-utils' | ||
import Login from '../login' | ||
|
||
// If you render your components with renderIntoDocument via react-testing-library | ||
// then you can get automatic cleanup of any components rendered like this: | ||
afterEach(cleanup) | ||
|
||
test('calls onSubmit with the username and password when submitted', () => { | ||
// Arrange | ||
const fakeUser = generate.loginForm() | ||
const handleSubmit = jest.fn() | ||
const {getByLabelText, getByText} = renderIntoDocument( | ||
<Login onSubmit={handleSubmit} />, | ||
) | ||
|
||
const usernameNode = getByLabelText('username') | ||
const passwordNode = getByLabelText('password') | ||
|
||
// Act | ||
usernameNode.value = fakeUser.username | ||
passwordNode.value = fakeUser.password | ||
getByText('submit').click() | ||
|
||
// Assert | ||
expect(handleSubmit).toHaveBeenCalledTimes(1) | ||
expect(handleSubmit).toHaveBeenCalledWith(fakeUser) | ||
}) |
Oops, something went wrong.