Skip to content

Commit

Permalink
docs: update complex example (#806)
Browse files Browse the repository at this point in the history
Co-authored-by: Lidor Avitan <[email protected]>
  • Loading branch information
lidoravitan and Lidor Avitan authored Oct 26, 2020
1 parent d9a36fa commit 332a6d5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ function Login() {
password: passwordInput.value,
}),
})
.then(r => r.json())
.then((r) =>
r.json().then((data) => (r.ok ? data : Promise.reject(data)))
)
.then(
user => {
setState({loading: false, resolved: true, error: null})
Expand Down Expand Up @@ -282,9 +284,10 @@ import {setupServer} from 'msw/node'
import {render, fireEvent, screen} from '@testing-library/react'
import Login from '../login'

const fakeUserResponse = { token: 'fake_user_token' }
const server = setupServer(
rest.post('/api/login', (req, res, ctx) => {
return res(ctx.json({token: 'fake_user_token'}))
return res(ctx.json(fakeUserResponse))
}),
)

Expand Down Expand Up @@ -322,7 +325,7 @@ test('allows the user to login successfully', async () => {
test('handles server exceptions', async () => {
// mock the server error response for this test suite only.
server.use(
rest.post('/', (req, res, ctx) => {
rest.post('/api/login', (req, res, ctx) => {
return res(ctx.status(500), ctx.json({message: 'Internal server error'}))
}),
)
Expand Down

0 comments on commit 332a6d5

Please sign in to comment.