Skip to content

Commit 872bd6a

Browse files
authored
docs: Add window.localStorage.remove('token') statement to afterEach() in __tests__/login.js file (#709)
Due to the first test suite, I need to remove the token value generated from local storage. The second test suite will fail if the token value is not removed.
1 parent fd89e1e commit 872bd6a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ should be installed as one of your project's `devDependencies`:
101101
```
102102
npm install --save-dev @testing-library/react
103103
```
104+
104105
or
105106

106107
for installation via [yarn](https://classic.yarnpkg.com/en/)
108+
107109
```
108110
yarn add --dev @testing-library/react
109111
```
@@ -283,11 +285,14 @@ import Login from '../login'
283285
const server = setupServer(
284286
rest.post('/api/login', (req, res, ctx) => {
285287
return res(ctx.json({token: 'fake_user_token'}))
286-
})
288+
}),
287289
)
288290

289291
beforeAll(() => server.listen())
290-
afterEach(() => server.resetHandlers())
292+
afterEach(() => {
293+
server.resetHandlers()
294+
window.localStorage.removeItem('token')
295+
})
291296
afterAll(() => server.close())
292297

293298
test('allows the user to login successfully', async () => {
@@ -318,11 +323,8 @@ test('handles server exceptions', async () => {
318323
// mock the server error response for this test suite only.
319324
server.use(
320325
rest.post('/', (req, res, ctx) => {
321-
return res(
322-
ctx.status(500),
323-
ctx.json({message: 'Internal server error'}),
324-
)
325-
})
326+
return res(ctx.status(500), ctx.json({message: 'Internal server error'}))
327+
}),
326328
)
327329

328330
render(<Login />)
@@ -591,6 +593,7 @@ Thanks goes to these people ([emoji key][emojis]):
591593
592594
<!-- markdownlint-enable -->
593595
<!-- prettier-ignore-end -->
596+
594597
<!-- ALL-CONTRIBUTORS-LIST:END -->
595598
596599
This project follows the [all-contributors][all-contributors] specification.

0 commit comments

Comments
 (0)