|
1 | 1 | import * as React from 'react'; |
2 | 2 | import { Store } from '@reduxjs/toolkit'; |
3 | | -import { render, fireEvent } from '@testing-library/react'; |
| 3 | +import { render, fireEvent, waitFor } from '@testing-library/react'; |
4 | 4 | import { Provider } from 'react-redux'; |
5 | 5 | import { ThemeProvider } from 'styles/theme/ThemeProvider'; |
6 | 6 | import { HelmetProvider } from 'react-helmet-async'; |
@@ -76,33 +76,45 @@ describe('<GithubRepoForm />', () => { |
76 | 76 | expect(component.container.querySelector('circle')).toBeInTheDocument(); |
77 | 77 | }); |
78 | 78 |
|
79 | | - it('should display list when repos not empty', () => { |
| 79 | + it('should display list when repos not empty', async () => { |
80 | 80 | const repoName = 'testRepo'; |
81 | 81 | store.dispatch( |
82 | 82 | actions.reposLoaded([{ id: 'test', name: repoName } as any]), |
83 | 83 | ); |
84 | | - expect(component.queryByText(repoName)).toBeInTheDocument(); |
| 84 | + await waitFor(() => |
| 85 | + expect(component.queryByText(repoName)).toBeInTheDocument(), |
| 86 | + ); |
85 | 87 | }); |
86 | 88 |
|
87 | | - it('should display error when repoError fired', () => { |
| 89 | + it('should display error when repoError fired', async () => { |
88 | 90 | let error = RepoErrorType.USER_NOT_FOUND; |
89 | 91 | store.dispatch(actions.repoError(error)); |
90 | | - expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); |
| 92 | + await waitFor(() => |
| 93 | + expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(), |
| 94 | + ); |
91 | 95 |
|
92 | 96 | error = RepoErrorType.USER_HAS_NO_REPO; |
93 | 97 | store.dispatch(actions.repoError(error)); |
94 | | - expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); |
| 98 | + await waitFor(() => |
| 99 | + expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(), |
| 100 | + ); |
95 | 101 |
|
96 | 102 | error = RepoErrorType.USERNAME_EMPTY; |
97 | 103 | store.dispatch(actions.repoError(error)); |
98 | | - expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); |
| 104 | + await waitFor(() => |
| 105 | + expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(), |
| 106 | + ); |
99 | 107 |
|
100 | 108 | error = RepoErrorType.RESPONSE_ERROR; |
101 | 109 | store.dispatch(actions.repoError(error)); |
102 | | - expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); |
| 110 | + await waitFor(() => |
| 111 | + expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(), |
| 112 | + ); |
103 | 113 |
|
104 | 114 | error = RepoErrorType.GITHUB_RATE_LIMIT; |
105 | 115 | store.dispatch(actions.repoError(error)); |
106 | | - expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(); |
| 116 | + await waitFor(() => |
| 117 | + expect(component.queryByText(repoErrorText(error))).toBeInTheDocument(), |
| 118 | + ); |
107 | 119 | }); |
108 | 120 | }); |
0 commit comments