test-utils.ts 835 B

1234567891011121314151617181920212223
  1. // 测试工具函数
  2. import { render, type RenderResult } from '@testing-library/react'
  3. export const renderTaroComponent = (component: React.ReactElement, options?: any): RenderResult => {
  4. return render(component, options)
  5. }
  6. // 其他通用的测试工具函数可以在这里添加
  7. export const waitForUpdate = async (timeout = 100) => {
  8. await new Promise(resolve => setTimeout(resolve, timeout))
  9. }
  10. export const mockConsole = {
  11. error: jest.spyOn(console, 'error').mockImplementation(() => {}),
  12. warn: jest.spyOn(console, 'warn').mockImplementation(() => {}),
  13. log: jest.spyOn(console, 'log').mockImplementation(() => {}),
  14. info: jest.spyOn(console, 'info').mockImplementation(() => {}),
  15. debug: jest.spyOn(console, 'debug').mockImplementation(() => {})
  16. }
  17. export const restoreConsole = () => {
  18. jest.restoreAllMocks()
  19. }