mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
test(frontend): replace jest with vitest
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
5241a6e988
commit
49bbd32635
188 changed files with 1364 additions and 1212 deletions
|
@ -6,6 +6,7 @@
|
|||
import type { CheatsheetSearchIndexEntry } from './use-cheatsheet-search'
|
||||
import { useCheatsheetSearch } from './use-cheatsheet-search'
|
||||
import { renderHook, waitFor } from '@testing-library/react'
|
||||
import { describe, expect, it, beforeAll, afterAll } from 'vitest'
|
||||
|
||||
describe('useDocumentSearch', () => {
|
||||
const searchEntries: CheatsheetSearchIndexEntry[] = [
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import { useIsDocumentVisible } from './use-is-document-visible'
|
||||
import { fireEvent, render } from '@testing-library/react'
|
||||
import React, { Fragment } from 'react'
|
||||
import { describe, expect, it, beforeAll, afterAll } from 'vitest'
|
||||
|
||||
describe('use is document visible', () => {
|
||||
const TestComponent: React.FC = () => {
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
import { useLowercaseOnInputChange } from './use-lowercase-on-input-change'
|
||||
import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { describe, expect, it, vitest, beforeAll, afterAll } from 'vitest'
|
||||
|
||||
describe('useOnInputChange', () => {
|
||||
it('executes the setter', async () => {
|
||||
const callback = jest.fn()
|
||||
const callback = vitest.fn()
|
||||
const testValue = 'TEST VALUE'
|
||||
|
||||
const Test: React.FC = () => {
|
||||
|
|
|
@ -6,10 +6,11 @@
|
|||
import { useOnInputChange } from './use-on-input-change'
|
||||
import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { describe, expect, it, vitest, beforeAll, afterAll } from 'vitest'
|
||||
|
||||
describe('useOnInputChange', () => {
|
||||
it('executes the setter', async () => {
|
||||
const callback = jest.fn()
|
||||
const callback = vitest.fn()
|
||||
const testValue = 'testValue'
|
||||
|
||||
const Test: React.FC = () => {
|
||||
|
|
|
@ -5,22 +5,24 @@
|
|||
*/
|
||||
import { useTranslatedText } from './use-translated-text'
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import type { UseTranslationResponse } from 'react-i18next'
|
||||
import * as ReactI18NextModule from 'react-i18next'
|
||||
import { Mock } from 'ts-mockery'
|
||||
import type { UseTranslationResponse } from 'react-i18next'
|
||||
import { beforeEach, describe, expect, it, vitest, beforeAll, afterAll } from 'vitest'
|
||||
import { vi } from 'vitest'
|
||||
|
||||
jest.mock('react-i18next')
|
||||
vi.mock('react-i18next')
|
||||
|
||||
describe('useTranslatedText', () => {
|
||||
const mockTranslation = 'mockTranslation'
|
||||
const mockKey = 'mockKey'
|
||||
const translateFunction = jest.fn(() => mockTranslation)
|
||||
const translateFunction = vitest.fn(() => mockTranslation)
|
||||
|
||||
beforeEach(() => {
|
||||
const useTranslateMock = Mock.of({
|
||||
t: translateFunction
|
||||
}) as unknown as UseTranslationResponse<never, never>
|
||||
jest.spyOn(ReactI18NextModule, 'useTranslation').mockReturnValue(useTranslateMock)
|
||||
vitest.spyOn(ReactI18NextModule, 'useTranslation').mockReturnValue(useTranslateMock)
|
||||
})
|
||||
|
||||
it('translates text', () => {
|
||||
|
|
|
@ -7,8 +7,10 @@ import * as UseDarkModeStateModule from './use-dark-mode-state'
|
|||
import { useOutlineButtonVariant } from './use-outline-button-variant'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import React from 'react'
|
||||
import { describe, it, vitest } from 'vitest'
|
||||
import { vi } from 'vitest'
|
||||
|
||||
jest.mock('./use-dark-mode-state')
|
||||
vi.mock('./use-dark-mode-state')
|
||||
|
||||
describe('useOutlineButtonVariant', () => {
|
||||
const TestComponent: React.FC = () => {
|
||||
|
@ -16,13 +18,13 @@ describe('useOutlineButtonVariant', () => {
|
|||
}
|
||||
|
||||
it('returns the correct variant for dark mode', async () => {
|
||||
jest.spyOn(UseDarkModeStateModule, 'useDarkModeState').mockReturnValue(true)
|
||||
vitest.spyOn(UseDarkModeStateModule, 'useDarkModeState').mockReturnValue(true)
|
||||
render(<TestComponent />)
|
||||
await screen.findByText('outline-light')
|
||||
})
|
||||
|
||||
it('returns the correct variant for light mode', async () => {
|
||||
jest.spyOn(UseDarkModeStateModule, 'useDarkModeState').mockReturnValue(false)
|
||||
vitest.spyOn(UseDarkModeStateModule, 'useDarkModeState').mockReturnValue(false)
|
||||
render(<TestComponent />)
|
||||
await screen.findByText('outline-dark')
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue