mirror of
https://github.com/fergalmoran/onearmy-community-platform.git
synced 2026-01-06 17:03:58 +00:00
fix: handle jest console warnings
This commit is contained in:
committed by
benfurber
parent
634007f270
commit
f96cd3cf5a
@@ -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'
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user