/
githubmirror
/
redux
Обзор
Документация
Войти
/
githubmirror
/
redux
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/utils/warning.spec.ts
40 строк
1 KB
Mark Erikson
Switch tests to Vitest
13 фев 2023, 05:45
13 фев 2023, 05:45
4a35430
Код
Авторство
О чём код?
/* eslint-disable no-console */ import { vi } from 'vitest' import warning from '@internal/utils/warning' describe('Utils', () => { describe('warning', () => { it('calls console.error when available', () => { const preSpy = console.error const spy = vi.fn() console.error = spy try { warning('Test') expect(spy.mock.calls[0][0]).toBe('Test') } finally { spy.mockClear() console.error = preSpy } }) it('does not throw when console.error is not available', () => { const realConsole = global.console Object.defineProperty(global, 'console', { value: {} }) try { expect(() => warning('Test')).not.toThrow() } finally { Object.defineProperty(global, 'console', { value: realConsole }) } }) it('does not throw when console is not available', () => { const realConsole = global.console Object.defineProperty(global, 'console', { value: undefined }) try { expect(() => warning('Test')).not.toThrow() } finally { Object.defineProperty(global, 'console', { value: realConsole }) } }) }) })