Skip to content

Commit

Permalink
docs: Add window.localStorage.remove('token') statement to afterEach(…
Browse files Browse the repository at this point in the history
…) 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.
  • Loading branch information
2dubbing committed Jun 15, 2020
1 parent fd89e1e commit 872bd6a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Expand Up @@ -101,9 +101,11 @@ should be installed as one of your project's `devDependencies`:
```
npm install --save-dev @testing-library/react
```

or

for installation via [yarn](https://classic.yarnpkg.com/en/)

```
yarn add --dev @testing-library/react
```
Expand Down Expand Up @@ -283,11 +285,14 @@ import Login from '../login'
const server = setupServer(
rest.post('/api/login', (req, res, ctx) => {
return res(ctx.json({token: 'fake_user_token'}))
})
}),
)

beforeAll(() => server.listen())
afterEach(() => server.resetHandlers())
afterEach(() => {
server.resetHandlers()
window.localStorage.removeItem('token')
})
afterAll(() => server.close())

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

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

0 comments on commit 872bd6a

Please sign in to comment.