Skip to content

Commit

Permalink
test(sanity): migrate remaining tests to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Oct 14, 2024
1 parent 2cc7ea0 commit 261d657
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {beforeAll, describe, expect, it, jest} from '@jest/globals'
import {render, screen} from '@testing-library/react'
import {type SanityClient} from 'sanity'
import {beforeAll, describe, expect, it, vi} from 'vitest'

import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient'
import {createTestProvider} from '../../../../test/testUtils/TestProvider'
import {FormBuilderInputErrorBoundary} from './FormBuilderInputErrorBoundary'

jest.mock('use-hot-module-reload', () => ({
useHotModuleReload: jest.fn(),
vi.mock('use-hot-module-reload', () => ({
useHotModuleReload: vi.fn(),
}))

describe('FormBuilderInputErrorBoundary', () => {
beforeAll(() => {
jest.clearAllMocks()
vi.clearAllMocks()
})

it('renders children when there is no error', async () => {
Expand All @@ -26,7 +26,7 @@ describe('FormBuilderInputErrorBoundary', () => {
})

it('calls onUncaughtError when an error is caught', async () => {
const onUncaughtError = jest.fn()
const onUncaughtError = vi.fn()

const ThrowErrorComponent = () => {
throw new Error('An EXPECTED, testing error occurred!')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, it} from '@jest/globals'
import {describe, expect, it} from 'vitest'

import {discardChainTo, toOrderedChains} from '../eventChainUtils'
import {mutationEvent} from './test-utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-nested-ternary */
import {expect, test} from '@jest/globals'
import {from, lastValueFrom} from 'rxjs'
import {toArray} from 'rxjs/operators'
import {expect, test} from 'vitest'

import {type MutationPayload} from '../../buffered-doc'
import {type ListenerEvent} from '../../getPairListener'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import {describe, expect, it, jest} from '@jest/globals'
import {render, screen} from '@testing-library/react'
import {type SanityClient, type Workspace} from 'sanity'
import {describe, expect, it, vi} from 'vitest'

import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient'
import {createTestProvider} from '../../../../test/testUtils/TestProvider'
import {WorkspaceRouterProvider} from './WorkspaceRouterProvider'

jest.mock('../router/RouterHistoryContext', () => ({
vi.mock('../router/RouterHistoryContext', () => ({
useRouterHistory: () => ({
location: {pathname: '/'},
listen: jest.fn(),
listen: vi.fn(),
}),
}))

jest.mock('../router', () => ({
vi.mock('../router', () => ({
createRouter: () => ({
getBasePath: jest.fn(),
decode: jest.fn(),
isNotFound: jest.fn(),
getBasePath: vi.fn(),
decode: vi.fn(),
isNotFound: vi.fn(),
}),
}))

jest.mock('sanity/router', () => ({
vi.mock('sanity/router', () => ({
RouterProvider: ({children}: {children: React.ReactNode}) => <div>{children}</div>,
IntentLink: () => <div>IntentLink</div>,
}))

jest.mock('./WorkspaceRouterProvider', () => ({
...(jest.requireActual('./WorkspaceRouterProvider') as object),
useRouterFromWorkspaceHistory: jest.fn(),
vi.mock('./WorkspaceRouterProvider', async () => ({
...(await vi.importActual('./WorkspaceRouterProvider')),
useRouterFromWorkspaceHistory: vi.fn(),
}))

describe('WorkspaceRouterProvider', () => {
Expand All @@ -52,7 +52,7 @@ describe('WorkspaceRouterProvider', () => {
currentUser: {},
authenticated: true,
auth: {},
getClient: jest.fn(),
getClient: vi.fn(),
i18n: {},
__internal: {},
type: 'workspace',
Expand All @@ -70,7 +70,7 @@ describe('WorkspaceRouterProvider', () => {
})

it('calls onUncaughtError when an error is caught', async () => {
const onUncaughtError = jest.fn()
const onUncaughtError = vi.fn()

const ThrowErrorComponent = () => {
throw new Error('An EXPECTED, testing error occurred!')
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/util/__tests__/rxSwr.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, expect, it} from '@jest/globals'
import {lastValueFrom, timer} from 'rxjs'
import {map, toArray} from 'rxjs/operators'
import {describe, expect, it} from 'vitest'

import {createSWR} from '../rxSwr'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {beforeAll, describe, expect, it, jest} from '@jest/globals'
import {studioTheme, ThemeProvider} from '@sanity/ui'
import {render} from '@testing-library/react'
import {type SanityClient} from 'sanity'
import {beforeAll, describe, expect, it, vi} from 'vitest'

import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient'
import {createTestProvider} from '../../../../test/testUtils/TestProvider'
Expand All @@ -11,12 +11,12 @@ import {ErrorBoundary} from '../ErrorBoundary'

describe('ErrorBoundary', () => {
beforeAll(() => {
jest.clearAllMocks()
vi.clearAllMocks()
})

it('calls onUncaughtError when an error is caught', async () => {
const onUncaughtError = jest.fn()
const onCatch = jest.fn()
const onUncaughtError = vi.fn()
const onCatch = vi.fn()

const ThrowErrorComponent = () => {
throw new Error('An EXPECTED, testing error occurred!')
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('ErrorBoundary', () => {
})

it('calls onCatch prop when an error is caught when no onUncaughtError exists', () => {
const onCatch = jest.fn()
const onCatch = vi.fn()

const WrapperWithoutError = ({children}: {children: React.ReactNode}) => {
const locales = [usEnglishLocale]
Expand Down

0 comments on commit 261d657

Please sign in to comment.