Last active
October 5, 2020 13:19
-
-
Save itaditya/83fe9a61f3f09557198f2f3df167e008 to your computer and use it in GitHub Desktop.
(Blog) Testing a Redux hooked app
This file contains hidden or 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
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import { render, screen, waitForElementToBeRemoved } from '@testing-library/react'; | |
import '@testing-library/jest-dom/extend-expect'; | |
import App from './App'; | |
import { createReduxStore } from './redux'; | |
describe('Test App', () => { | |
function renderApp(store = createReduxStore(), props = {}) { | |
return render( | |
<Provider store={store}> | |
<App {...props} /> | |
</Provider>, | |
); | |
} | |
test('show loading indicator till API responds', async () => { | |
renderApp(); | |
// during loading, show app name and loading indicator | |
expect(screen.getByRole('heading')).toHaveTextContent('Ordux'); | |
expect(screen.getByRole('status')).toHaveTextContent('Loading...'); | |
await waitForElementToBeRemoved(() => screen.getByText(/Loading/i)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment