refactor & perf: import { noop } from 'lodash-es' across web (#17439)

This commit is contained in:
yusheng chen
2025-04-06 17:56:08 +08:00
committed by GitHub
parent 7016ccef10
commit c05e03fc09
87 changed files with 271 additions and 184 deletions

View File

@ -2,6 +2,7 @@ import React from 'react'
import { act, render, screen, waitFor } from '@testing-library/react'
import Toast, { ToastProvider, useToastContext } from '.'
import '@testing-library/jest-dom'
import { noop } from 'lodash-es'
// Mock timers for testing timeouts
jest.useFakeTimers()
@ -76,11 +77,11 @@ describe('Toast', () => {
test('does not render close button when close is undefined', () => {
// Create a modified context where close is undefined
const CustomToastContext = React.createContext({ notify: () => { }, close: undefined })
const CustomToastContext = React.createContext({ notify: noop, close: undefined })
// Create a wrapper component using the custom context
const Wrapper = ({ children }: any) => (
<CustomToastContext.Provider value={{ notify: () => { }, close: undefined }}>
<CustomToastContext.Provider value={{ notify: noop, close: undefined }}>
{children}
</CustomToastContext.Provider>
)

View File

@ -12,6 +12,7 @@ import {
import { createContext, useContext } from 'use-context-selector'
import ActionButton from '@/app/components/base/action-button'
import classNames from '@/utils/classnames'
import { noop } from 'lodash-es'
export type IToastProps = {
type?: 'success' | 'error' | 'warning' | 'info'
@ -134,7 +135,7 @@ Toast.notify = ({
root.render(
<ToastContext.Provider value={{
notify: () => { },
notify: noop,
close: () => {
if (holder) {
root.unmount()