fix: handle jest console warnings

This commit is contained in:
Kim Skovhus Andersen
2024-07-08 23:28:09 +02:00
committed by benfurber
parent 634007f270
commit f96cd3cf5a
9 changed files with 36 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
import '@testing-library/jest-dom/vitest'
import { act } from 'react-dom/test-utils'
import { act } from 'react'
import { fireEvent, waitFor } from '@testing-library/react'
import { describe, expect, it } from 'vitest'

View File

@@ -1,4 +1,4 @@
import { act } from 'react-dom/test-utils'
import { act } from 'react'
import { useLocation } from 'react-router-dom'
import { render } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'

View File

@@ -19,7 +19,8 @@ const type = 'pretty'
export const logger = new Logger({
type,
minLevel: levelNumberToNameMap[logLevel],
minLevel:
process.env.NODE_ENV === 'test' ? 999 : levelNumberToNameMap[logLevel],
hideLogPositionForProduction: true,
})

View File

@@ -51,14 +51,16 @@ import { IModerationStatus } from 'oa-shared'
import { Howto } from './Howto'
const factory = (howtoStore?: Partial<HowtoStore>) => {
const router = createMemoryRouter(
createRoutesFromElements(
<Route path="/howto/:slug" key={1} element={<Howto />} />,
),
{
initialEntries: ['/howto/article'],
},
)
let router
act(() => {
router = createMemoryRouter(
createRoutesFromElements(
<Route path="/howto/:slug" key={1} element={<Howto />} />,
),
{ initialEntries: ['/howto/article'] },
)
})
return render(
<Provider howtoStore={howtoStore}>
@@ -85,11 +87,12 @@ describe('Howto', () => {
})
})
it('hides feedback when how-to is accepted', () => {
it('hides feedback when how-to is accepted', async () => {
let wrapper
act(() => {
howto.moderation = IModerationStatus.ACCEPTED
howto.moderatorFeedback = 'Moderation comments'
howto.moderation = IModerationStatus.ACCEPTED
howto.moderatorFeedback = 'Moderation comments'
await act(async () => {
wrapper = factory()
})
@@ -135,7 +138,7 @@ describe('Howto', () => {
let wrapper
howto._createdBy = 'NotHowtoAuthor'
act(() => {
await act(async () => {
wrapper = factory()
})

View File

@@ -142,6 +142,10 @@ describe('question.routes', () => {
wrapper = renderFn('/questions')
})
expect(wrapper.getByText(/loading/)).toBeInTheDocument()
await waitFor(() => {
expect(() => wrapper.getByText(/loading/)).toThrow()
})
})
it('renders an empty state', async () => {
@@ -404,7 +408,9 @@ describe('question.routes', () => {
await userEvent.clear(description)
await userEvent.type(description, 'Question description')
submitButton.click()
act(() => {
submitButton.click()
})
expect(mockUpsertQuestion).toHaveBeenCalledWith(
expect.objectContaining({

View File

@@ -105,7 +105,7 @@ describe('Research Article', () => {
})
})
it('does not display contributors when undefined', () => {
it('does not display contributors when undefined', async () => {
// Arrange
;(useResearchStore as Mock).mockReturnValue({
...mockResearchStore,
@@ -116,7 +116,7 @@ describe('Research Article', () => {
// Act
let wrapper
act(() => {
await act(async () => {
wrapper = getWrapper()
})

View File

@@ -167,7 +167,7 @@ describe('UserSettings', () => {
})
})
it('does not show moderation comments for approved pin', () => {
it('does not show moderation comments for approved pin', async () => {
mockUser = FactoryUser({ profileType: 'workspace' })
mockGetPin.mockResolvedValue(
FactoryMapPin({
@@ -177,7 +177,7 @@ describe('UserSettings', () => {
)
// Act
let wrapper
act(() => {
await act(async () => {
wrapper = Wrapper(mockUser)
})

View File

@@ -290,7 +290,7 @@ describe('discussion.store', () => {
//Act
expect(() =>
store.editComment(discussionItem, 'fake-comment-id', 'Edited comment'),
).rejects.toThrowError()
).rejects.toThrowError('Comment not editable by user')
// Assert
expect(setFn).not.toHaveBeenCalled()
@@ -356,7 +356,7 @@ describe('discussion.store', () => {
//Act
expect(() =>
store.deleteComment(discussionItem, 'fake-comment-id'),
).rejects.toThrowError()
).rejects.toThrowError('Comment not editable by user')
// Assert
expect(setFn).not.toHaveBeenCalled()

View File

@@ -120,7 +120,9 @@ export class QuestionStore extends ModuleStore {
images,
moderation,
})
logger.info(`upsertQuestion.set`, { dbRef })
if (process.env.NODE_ENV !== 'test') {
logger.info(`upsertQuestion.set`, { dbRef })
}
return dbRef.get() || null
}