Skip to content

Commit

Permalink
getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Jun 24, 2020
1 parent 28a5ba9 commit 3b7a472
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
26 changes: 12 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/__tests__/book-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import {
render,
screen,
act,
waitForLoadingToFinish,
userEvent,
loginAsUser,
Expand Down Expand Up @@ -163,9 +164,12 @@ test('can edit a note', async () => {
userEvent.type(notesTextarea, newNotes)

// wait for the loading spinner to show up
await screen.findByLabelText(/loading/i, undefined, {timeout: 500})
await screen.findByLabelText(/loading/i)
// wait for the loading spinner to go away
await waitForLoadingToFinish({timeout: 500})
await waitForLoadingToFinish()
// TODO: other tests fail when I remove this next line
// figure out why and remove it.
act(() => jest.advanceTimersByTime(1))

expect(notesTextarea.value).toBe(newNotes)

Expand Down
5 changes: 5 additions & 0 deletions src/components/__mocks__/profiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// we have this mock here so the profiler doesn't actually
// attempt to send profile reports during tests.
const Profiler = ({children}) => children

export {Profiler}
3 changes: 3 additions & 0 deletions src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import * as usersDB from 'test/data/users'
import * as listItemsDB from 'test/data/list-items'
import * as booksDB from 'test/data/books'

// we don't need the profiler in tests
jest.mock('components/profiler')

// set the location to the /list route as we auto-redirect users to that route
window.history.pushState({}, 'Home page', '/list')

Expand Down
4 changes: 0 additions & 4 deletions src/test/app-test-utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {queryCache} from 'react-query'
import {render as rtlRender, screen, waitFor} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import * as auth from 'auth-provider'
Expand Down Expand Up @@ -37,9 +36,6 @@ async function loginAsUser(userProperties) {
function waitForLoadingToFinish() {
return waitFor(
() => {
if (queryCache.isFetching) {
throw new Error('The react-query queryCache is still fetching')
}
if (
screen.queryAllByLabelText(/loading/i).length ||
screen.queryAllByText(/loading/i).length
Expand Down

0 comments on commit 3b7a472

Please sign in to comment.