Skip to content

Instantly share code, notes, and snippets.

@itaditya
Last active October 5, 2020 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itaditya/83fe9a61f3f09557198f2f3df167e008 to your computer and use it in GitHub Desktop.
Save itaditya/83fe9a61f3f09557198f2f3df167e008 to your computer and use it in GitHub Desktop.
(Blog) Testing a Redux hooked app
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