level_0
int64
0
10k
index
int64
0
0
repo_id
stringlengths
22
152
file_path
stringlengths
41
203
content
stringlengths
11
11.5M
9,810
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/ButtonTabControl.test.tsx
import ButtonTabControl from "./ButtonTabControl"; const requiredParams = { evaluatedValue: undefined, widgetProperties: undefined, parentPropertyName: "", parentPropertyValue: undefined, additionalDynamicData: {}, label: "", propertyName: "", controlType: "", isBindProperty: false, isTriggerProper...
9,814
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/ColorPickerComponentV2.test.tsx
import React from "react"; import { Provider } from "react-redux"; import "@testing-library/jest-dom"; import { render, screen, waitForElementToBeRemoved, } from "@testing-library/react"; import { ThemeProvider } from "styled-components"; import ColorPickerComponent from "./ColorPickerComponentV2"; import { light...
9,816
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/ColorPickerControl.test.tsx
import ColorPickerControl from "./ColorPickerControl"; const requiredParams = { evaluatedValue: undefined, widgetProperties: undefined, parentPropertyName: "", parentPropertyValue: undefined, additionalDynamicData: {}, label: "", propertyName: "", controlType: "", isBindProperty: false, isTriggerPr...
9,823
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/DropDownControl.test.tsx
import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig"; import { noop } from "lodash"; import type { DropDownControlProps } from "./DropDownControl"; import DropDownControl from "./DropDownControl"; const requiredParams: DropDownControlProps = { evaluatedValue: undefined, widgetPropertie...
9,827
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/IconSelectControl.test.tsx
import React from "react"; import "@testing-library/jest-dom"; import { render, screen, waitFor, waitForElementToBeRemoved, } from "@testing-library/react"; import IconSelectControl from "./IconSelectControl"; import userEvent from "@testing-library/user-event"; import { noop } from "lodash"; import { EditorThe...
9,829
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/IconTabControl.test.tsx
import IconTabControl from "./IconTabControl"; const requiredParams = { evaluatedValue: undefined, widgetProperties: undefined, parentPropertyName: "", parentPropertyValue: undefined, additionalDynamicData: {}, label: "", propertyName: "", controlType: "", isBindProperty: false, isTriggerProperty: ...
9,840
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/NumericInputControl.test.ts
import NumericInputControl from "./NumericInputControl"; const config = { evaluatedValue: undefined, widgetProperties: undefined, parentPropertyName: "", parentPropertyValue: undefined, additionalDynamicData: {}, label: "", propertyName: "", controlType: "", isBindProperty: false, isTriggerProperty...
9,851
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/StepControl.test.tsx
import StepControl from "./StepControl"; const requiredParams = { evaluatedValue: undefined, widgetProperties: undefined, parentPropertyName: "", parentPropertyValue: undefined, additionalDynamicData: {}, label: "", propertyName: "", controlType: "", isBindProperty: false, isTriggerProperty: false,...
9,854
0
petrpan-code/appsmithorg/appsmith/app/client/src/components
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/SwitchControl.test.tsx
import SwitchControl from "./SwitchControl"; const requiredParams = { evaluatedValue: undefined, widgetProperties: undefined, parentPropertyName: "", parentPropertyValue: undefined, additionalDynamicData: {}, label: "", propertyName: "", controlType: "", isBindProperty: false, isTriggerProperty: fa...
9,863
0
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls
petrpan-code/appsmithorg/appsmith/app/client/src/components/propertyControls/__snapshots__/IconSelectControl.test.tsx.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`<IconSelectControl /> - (none) icon Should display (none) icon when hideNoneIcon property is false/undefined 1`] = ` DOMTokenList { "0": "bp3-fill", "1": "bp3-icon-(none)", "2": "bp3-text-overflow-ellipsis", } `; exports[`<IconSelectControl /> - (none) icon Sh...
9,911
0
petrpan-code/appsmithorg/appsmith/app/client/src
petrpan-code/appsmithorg/appsmith/app/client/src/constants/routes.test.ts
import urlBuilder from "@appsmith/entities/URLRedirect/URLAssembly"; import { builderURL, viewerURL } from "@appsmith/RouteBuilder"; describe("builderURL", () => { let location: typeof window.location; beforeAll(() => { location = window.location; delete (window as any).location; urlBuilder.updateURLPa...
9,975
0
petrpan-code/appsmithorg/appsmith/app/client/src/ee/entities
petrpan-code/appsmithorg/appsmith/app/client/src/ee/entities/DataTree/dataTreeJSAction.test.ts
export * from "ce/entities/DataTree/dataTreeJSAction.test";
45
0
petrpan-code/alibaba/hooks/packages/hooks/src
petrpan-code/alibaba/hooks/packages/hooks/src/__tests__/index.test.ts
import * as ahooks from '..'; describe('ahooks', () => { test('exports modules should be defined', () => { Object.keys(ahooks).forEach((module) => { expect(ahooks[module]).toBeDefined(); }); }); });
47
0
petrpan-code/alibaba/hooks/packages/hooks/src/createDeepCompareEffect
petrpan-code/alibaba/hooks/packages/hooks/src/createDeepCompareEffect/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import { useEffect, useLayoutEffect, useState } from 'react'; import { createDeepCompareEffect } from '../index'; describe('createDeepCompareEffect', () => { it('should work for useEffect', async () => { const useDeepCompareEffect = createDeepCompareEffec...
49
0
petrpan-code/alibaba/hooks/packages/hooks/src/createUpdateEffect
petrpan-code/alibaba/hooks/packages/hooks/src/createUpdateEffect/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import { useEffect, useLayoutEffect } from 'react'; import { createUpdateEffect } from '../index'; describe('createUpdateEffect', () => { it('should work for useEffect', () => { const useUpdateEffect = createUpdateEffect(useEffect); let mountedState = 1; ...
51
0
petrpan-code/alibaba/hooks/packages/hooks/src/createUseStorageState
petrpan-code/alibaba/hooks/packages/hooks/src/createUseStorageState/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import type { Options } from '../index'; import { createUseStorageState } from '../index'; class TestStorage implements Storage { [name: string]: any; length: number = 0; _values = new Map<string, string>(); clear(): void { this._values.clear(); ...
56
0
petrpan-code/alibaba/hooks/packages/hooks/src/useAntdTable
petrpan-code/alibaba/hooks/packages/hooks/src/useAntdTable/__tests__/index.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import { sleep } from '../../utils/testingHelpers'; import useAntdTable from '../index'; interface Query { current: number; pageSize: number; [key: string]: any; } describe('useAntdTable', () => { // jest.useFakeTimers(); let queryArgs: an...
66
0
petrpan-code/alibaba/hooks/packages/hooks/src/useAsyncEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useAsyncEffect/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useAsyncEffect from '../index'; import { useState } from 'react'; import { sleep } from '../../utils/testingHelpers'; describe('useAsyncEffect', () => { it('should work without clean up', async () => { const hook = renderHook(() => { const [x...
72
0
petrpan-code/alibaba/hooks/packages/hooks/src/useBoolean
petrpan-code/alibaba/hooks/packages/hooks/src/useBoolean/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useBoolean from '../index'; const setUp = (defaultValue?: boolean) => renderHook(() => useBoolean(defaultValue)); describe('useBoolean', () => { it('test on methods', async () => { const { result } = setUp(); expect(result.current[0]).toBe(fal...
77
0
petrpan-code/alibaba/hooks/packages/hooks/src/useClickAway
petrpan-code/alibaba/hooks/packages/hooks/src/useClickAway/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useClickAway from '../index'; describe('useClickAway', () => { let container: HTMLDivElement; let container1: HTMLDivElement; beforeEach(() => { container = document.createElement('div'); container1 = document.createElement('div'); containe...
87
0
petrpan-code/alibaba/hooks/packages/hooks/src/useControllableValue
petrpan-code/alibaba/hooks/packages/hooks/src/useControllableValue/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useControllableValue, { Options, Props } from '../index'; describe('useControllableValue', () => { const setUp = (props?: Props, options?: Options<any>): any => renderHook(() => useControllableValue(props, options)); it('defaultValue should work...
94
0
petrpan-code/alibaba/hooks/packages/hooks/src/useCookieState
petrpan-code/alibaba/hooks/packages/hooks/src/useCookieState/__tests__/index.test.tsx
import { renderHook, act } from '@testing-library/react'; import useCookieState from '../index'; import type { Options } from '../index'; import Cookies from 'js-cookie'; describe('useCookieState', () => { const setUp = (key: string, options: Options) => renderHook(() => { const [state, setState] = useCook...
101
0
petrpan-code/alibaba/hooks/packages/hooks/src/useCountDown
petrpan-code/alibaba/hooks/packages/hooks/src/useCountDown/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useCountDown, { Options } from '../index'; const setup = (options: Options = {}) => renderHook((props: Options = options) => useCountDown(props)); describe('useCountDown', () => { beforeAll(() => { jest.useFakeTimers({ legacyFakeTimers: false })...
108
0
petrpan-code/alibaba/hooks/packages/hooks/src/useCounter
petrpan-code/alibaba/hooks/packages/hooks/src/useCounter/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useCounter, { Options } from '../index'; const setUp = (init?: number, options?: Options) => renderHook(() => useCounter(init, options)); it('should init counter', () => { const { result } = setUp(100); const [current] = result.current; expect(cur...
113
0
petrpan-code/alibaba/hooks/packages/hooks/src/useCreation
petrpan-code/alibaba/hooks/packages/hooks/src/useCreation/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import { useState } from 'react'; import useCreation from '../index'; describe('useCreation', () => { class Foo { constructor() { this.data = Math.random(); } data: number; } const setUp = (): any => renderHook(() => { const ...
119
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDebounce
petrpan-code/alibaba/hooks/packages/hooks/src/useDebounce/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useDebounce from '../index'; import { sleep } from '../../utils/testingHelpers'; describe('useDebounce', () => { it('useDebounce wait:200ms', async () => { let mountedState = 0; const { result, rerender } = renderHook(() => useDebounce(mountedS...
124
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDebounceEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useDebounceEffect/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useDebounceEffect from '../index'; import { sleep } from '../../utils/testingHelpers'; let hook; describe('useDebounceEffect', () => { it('useDebounceEffect should work', async () => { let mountedState = 1; const mockEffect = jest.fn(() => {})...
129
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDebounceFn
petrpan-code/alibaba/hooks/packages/hooks/src/useDebounceFn/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import { sleep } from '../../utils/testingHelpers'; import useDebounceFn from '../index'; interface ParamsObj { fn: (...arg: any) => any; deps?: any[]; wait: number; } let count = 0; const debounceFn = (gap: number) => { count += gap; }; const setUp =...
134
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDeepCompareEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useDeepCompareEffect/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import { useState } from 'react'; import useDeepCompareEffect from '../index'; describe('useDeepCompareEffect', () => { it('test deep compare', async () => { const hook = renderHook(() => { const [x, setX] = useState(0); const [y, setY] = useS...
139
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDeepCompareLayoutEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useDeepCompareLayoutEffect/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import { useState } from 'react'; import useDeepCompareLayoutEffect from '../index'; describe('useDeepCompareLayoutEffect', () => { it('test deep compare', async () => { const hook = renderHook(() => { const [x, setX] = useState(0); const [y, ...
144
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDocumentVisibility
petrpan-code/alibaba/hooks/packages/hooks/src/useDocumentVisibility/__tests__/index.test.ts
import useDocumentVisibility from '../index'; import { renderHook, act } from '@testing-library/react'; const mockIsBrowser = jest.fn(); const mockDocumentVisibilityState = jest.spyOn(document, 'visibilityState', 'get'); jest.mock('../../utils/isBrowser', () => { return { __esModule: true, get default() { ...
147
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDrag
petrpan-code/alibaba/hooks/packages/hooks/src/useDrag/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import type { Options } from '../index'; import useDrag from '../index'; import type { BasicTarget } from '../../utils/domTarget'; const setup = <T>(data: T, target: BasicTarget, options?: Options) => renderHook((newData: T) => useDrag(newData ? newData : data, ta...
151
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDrop
petrpan-code/alibaba/hooks/packages/hooks/src/useDrop/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useDrop, { Options } from '../index'; import type { BasicTarget } from '../../utils/domTarget'; const setup = (target: unknown, options?: Options) => renderHook(() => useDrop(target as BasicTarget, options)); const events = {}; const mockTarget = { addEv...
157
0
petrpan-code/alibaba/hooks/packages/hooks/src/useDynamicList
petrpan-code/alibaba/hooks/packages/hooks/src/useDynamicList/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useDynamicList from '../index'; describe('useDynamicList', () => { const setUp = (props: any): any => renderHook(() => useDynamicList(props)); it('getKey should work', () => { const hook = setUp([1, 2, 3]); expect(hook.result.current.list[0]...
165
0
petrpan-code/alibaba/hooks/packages/hooks/src/useEventEmitter
petrpan-code/alibaba/hooks/packages/hooks/src/useEventEmitter/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import { useState } from 'react'; import useEventEmitter from '../index'; describe('useEventEmitter', () => { const setUp = (): any => renderHook(() => { const event$ = useEventEmitter<number>(); const [count, setCount] = useState(0); ev...
170
0
petrpan-code/alibaba/hooks/packages/hooks/src/useEventListener
petrpan-code/alibaba/hooks/packages/hooks/src/useEventListener/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useEventListener from '../index'; describe('useEventListener', () => { let container: HTMLDivElement; beforeEach(() => { container = document.createElement('div'); document.body.appendChild(container); }); afterEach(() => { document.body...
176
0
petrpan-code/alibaba/hooks/packages/hooks/src/useEventTarget
petrpan-code/alibaba/hooks/packages/hooks/src/useEventTarget/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useEventTarget from '../index'; describe('useEventTarget', () => { it('should work without initial value', async () => { const hook = renderHook(() => useEventTarget()); expect(hook.result.current[0]).toBeUndefined(); act(() => { hook...
182
0
petrpan-code/alibaba/hooks/packages/hooks/src/useExternal
petrpan-code/alibaba/hooks/packages/hooks/src/useExternal/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useExternal, { Options } from '../index'; import { fireEvent } from '@testing-library/react'; const setup = (path: string, options?: Options) => renderHook(() => useExternal(path, options)); describe('useExternal', () => { beforeEach(() => { docum...
189
0
petrpan-code/alibaba/hooks/packages/hooks/src/useFavicon
petrpan-code/alibaba/hooks/packages/hooks/src/useFavicon/__tests__/index.test.tsx
import { renderHook } from '@testing-library/react'; import useFavicon from '../index'; describe('useFavicon', () => { it('should set the favicon', () => { expect(document.querySelector("link[rel*='icon']")).toBeNull(); renderHook(() => useFavicon('favicon.ico')); expect(document.querySelector("link[rel*...
194
0
petrpan-code/alibaba/hooks/packages/hooks/src/useFocusWithin
petrpan-code/alibaba/hooks/packages/hooks/src/useFocusWithin/__tests__/index.test.tsx
import React, { useRef } from 'react'; import useFocusWithin, { Options } from '../index'; import { render, fireEvent } from '@testing-library/react'; const setup = (options?: Options) => { const TestComponent = () => { const ref = useRef(null); const isFocusWithin = useFocusWithin(ref, options); return ...
200
0
petrpan-code/alibaba/hooks/packages/hooks/src/useFullscreen
petrpan-code/alibaba/hooks/packages/hooks/src/useFullscreen/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useFullscreen from '../index'; import type { Options } from '../index'; import type { BasicTarget } from '../../utils/domTarget'; let globalHook: any; let targetEl: any; const events = { fullscreenchange: new Set(), fullscreenerror: new Set(), }; con...
210
0
petrpan-code/alibaba/hooks/packages/hooks/src/useFusionTable
petrpan-code/alibaba/hooks/packages/hooks/src/useFusionTable/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useFusionTable from '../index'; import { sleep } from '../../utils/testingHelpers'; type Result = { total: number; list: any[]; }; let count = 0; const total = 40; const getTableData = async ({ current, pageSize }): Promise<Result> => { if (count ...
219
0
petrpan-code/alibaba/hooks/packages/hooks/src/useGetState
petrpan-code/alibaba/hooks/packages/hooks/src/useGetState/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useGetState from '../index'; describe('useGetState', () => { const setUp = <T>(initialValue: T) => renderHook(() => { const [state, setState, getState] = useGetState<T>(initialValue); return { state, setState, ge...
224
0
petrpan-code/alibaba/hooks/packages/hooks/src/useHistoryTravel
petrpan-code/alibaba/hooks/packages/hooks/src/useHistoryTravel/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useHistoryTravel from '../index'; describe('useHistoryTravel', () => { it('should work without initial value', async () => { const hook = renderHook(() => useHistoryTravel()); expect(hook.result.current.value).toBeUndefined(); act(() => { ...
231
0
petrpan-code/alibaba/hooks/packages/hooks/src/useHover
petrpan-code/alibaba/hooks/packages/hooks/src/useHover/__tests__/index.test.tsx
// write your test cases here import React from 'react'; import { renderHook, act } from '@testing-library/react'; import { render, fireEvent } from '@testing-library/react'; import useHover from '../index'; describe('useHover', () => { it('should work', () => { const { getByText } = render(<button>Hover</button...
237
0
petrpan-code/alibaba/hooks/packages/hooks/src/useInViewport
petrpan-code/alibaba/hooks/packages/hooks/src/useInViewport/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useInViewport from '../index'; const targetEl = document.createElement('div'); document.body.appendChild(targetEl); const observe = jest.fn(); const disconnect = jest.fn(); const mockIntersectionObserver = jest.fn().mockReturnValue({ observe, disco...
245
0
petrpan-code/alibaba/hooks/packages/hooks/src/useInfiniteScroll
petrpan-code/alibaba/hooks/packages/hooks/src/useInfiniteScroll/__tests__/index.test.ts
import { useState } from 'react'; import { renderHook, act } from '@testing-library/react'; import useInfiniteScroll from '..'; import type { Data, Service, InfiniteScrollOptions } from '../types'; import { sleep } from '../../utils/testingHelpers'; let count = 0; export async function mockRequest() { await sleep(10...
254
0
petrpan-code/alibaba/hooks/packages/hooks/src/useInterval
petrpan-code/alibaba/hooks/packages/hooks/src/useInterval/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useInterval from '../index'; interface ParamsObj { fn: (...arg: any) => any; delay: number | undefined; options?: { immediate: boolean }; } const setUp = ({ fn, delay, options }: ParamsObj) => renderHook(() => useInterval(fn, delay, options)); descr...
260
0
petrpan-code/alibaba/hooks/packages/hooks/src/useIsomorphicLayoutEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useIsomorphicLayoutEffect/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useIsomorphicLayoutEffect from '../index'; describe('useIsomorphicLayoutEffect', () => { const callback = jest.fn(); const { result } = renderHook(() => useIsomorphicLayoutEffect(callback)); it('cheak return value', () => { expect(result.current).t...
264
0
petrpan-code/alibaba/hooks/packages/hooks/src/useKeyPress
petrpan-code/alibaba/hooks/packages/hooks/src/useKeyPress/__tests__/index.test.tsx
import { renderHook } from '@testing-library/react'; import { fireEvent } from '@testing-library/react'; import useKeyPress from '../index'; const callback = jest.fn(); afterEach(() => { callback.mockClear(); }); describe('useKeyPress ', () => { it('test single key', async () => { const { unmount } = renderH...
276
0
petrpan-code/alibaba/hooks/packages/hooks/src/useLatest
petrpan-code/alibaba/hooks/packages/hooks/src/useLatest/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useLatest from '../index'; const setUp = (val) => renderHook((state) => useLatest(state), { initialProps: val }); describe('useLatest', () => { it('useLatest with basic variable should work', async () => { const { result, rerender } = setUp(0); re...
281
0
petrpan-code/alibaba/hooks/packages/hooks/src/useLocalStorageState
petrpan-code/alibaba/hooks/packages/hooks/src/useLocalStorageState/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useLocalStorageState from '../index'; describe('useLocalStorageState', () => { const setUp = <T>(key: string, value: T) => renderHook(() => { const [state, setState] = useLocalStorageState<T>(key, { defaultValue: value }); return { ...
288
0
petrpan-code/alibaba/hooks/packages/hooks/src/useLockFn
petrpan-code/alibaba/hooks/packages/hooks/src/useLockFn/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import { useRef, useCallback, useState } from 'react'; import useLockFn from '../index'; import { sleep } from '../../utils/testingHelpers'; describe('useLockFn', () => { const setUp = (): any => renderHook(() => { const [tag, updateTag] = useState(...
293
0
petrpan-code/alibaba/hooks/packages/hooks/src/useLongPress
petrpan-code/alibaba/hooks/packages/hooks/src/useLongPress/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useLongPress from '../index'; import type { Options } from '../index'; const mockCallback = jest.fn(); const mockClickCallback = jest.fn(); const mockLongPressEndCallback = jest.fn(); let events = {}; const mockTarget = { addEventListener: jest.fn((event, ...
300
0
petrpan-code/alibaba/hooks/packages/hooks/src/useMap
petrpan-code/alibaba/hooks/packages/hooks/src/useMap/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useMap from '../index'; const setup = (initialMap?: Iterable<[any, any]>) => renderHook(() => useMap(initialMap)); describe('useMap', () => { it('should init map and utils', () => { const { result } = setup([ ['foo', 'bar'], ['a', 1], ...
305
0
petrpan-code/alibaba/hooks/packages/hooks/src/useMemoizedFn
petrpan-code/alibaba/hooks/packages/hooks/src/useMemoizedFn/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import { useState } from 'react'; import useMemoizedFn from '../'; const useCount = () => { const [count, setCount] = useState(0); const addCount = () => { setCount((c) => c + 1); }; const memoizedFn = useMemoizedFn(() => count); return { addCo...
311
0
petrpan-code/alibaba/hooks/packages/hooks/src/useMount
petrpan-code/alibaba/hooks/packages/hooks/src/useMount/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useMount from '../index'; describe('useMount', () => { it('test mount', async () => { const fn = jest.fn(); const hook = renderHook(() => useMount(fn)); expect(fn).toBeCalledTimes(1); hook.rerender(); expect(fn).toBeCalledTimes(1); h...
316
0
petrpan-code/alibaba/hooks/packages/hooks/src/useMouse
petrpan-code/alibaba/hooks/packages/hooks/src/useMouse/__tests__/index.test.ts
import { renderHook, waitFor } from '@testing-library/react'; import useMouse from '../index'; describe('useMouse', () => { function moveMouse(x: number, y: number) { document.dispatchEvent( new MouseEvent('mousemove', { clientX: x, clientY: y, screenX: x, screenY: y, ...
322
0
petrpan-code/alibaba/hooks/packages/hooks/src/useMutationObserver
petrpan-code/alibaba/hooks/packages/hooks/src/useMutationObserver/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useMutationObserver from '../index'; const options: MutationObserverInit = { attributes: true, childList: true }; describe('useMutationObserver', () => { let container: HTMLDivElement; beforeEach(() => { container = document.createElement('div'); ...
327
0
petrpan-code/alibaba/hooks/packages/hooks/src/useNetwork
petrpan-code/alibaba/hooks/packages/hooks/src/useNetwork/__tests__/index.test.ts
import useNetwork from '../index'; import { renderHook, act } from '@testing-library/react'; describe('useNetwork', () => { it('toggle network state', () => { const { result } = renderHook(() => useNetwork()); expect(result.current.online).toBeTruthy(); act(() => { window.dispatchEvent(new Event('o...
333
0
petrpan-code/alibaba/hooks/packages/hooks/src/usePagination
petrpan-code/alibaba/hooks/packages/hooks/src/usePagination/__tests__/index.test.ts
import { renderHook, act, waitFor } from '@testing-library/react'; import usePagination from '../'; // 初始化 // 基本 action // refreshDeps // cache describe('usePagination', () => { let queryArgs; const asyncFn = (query) => { queryArgs = query; return Promise.resolve({ current: query.current, tota...
341
0
petrpan-code/alibaba/hooks/packages/hooks/src/usePrevious
petrpan-code/alibaba/hooks/packages/hooks/src/usePrevious/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import type { ShouldUpdateFunc } from '../'; import usePrevious from '../'; describe('usePrevious', () => { function getHook<T>(initialValue?: T, compareFunction?: ShouldUpdateFunc<T>) { return renderHook(({ val, cmp }) => usePrevious<T>(val as T, cmp), { ...
347
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRafInterval
petrpan-code/alibaba/hooks/packages/hooks/src/useRafInterval/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useRafInterval from '../index'; interface ParamsObj { fn: (...arg: any) => any; delay: number | undefined; options?: { immediate: boolean }; } const setUp = ({ fn, delay, options }: ParamsObj) => renderHook(() => useRafInterval(fn, delay, options)); ...
354
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRafState
petrpan-code/alibaba/hooks/packages/hooks/src/useRafState/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useRafState from '../index'; describe('useRafState', () => { it('should work', () => { const mockRaf = jest .spyOn(window, 'requestAnimationFrame') .mockImplementation((cb: FrameRequestCallback) => { cb(0); return 0; ...
359
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRafTimeout
petrpan-code/alibaba/hooks/packages/hooks/src/useRafTimeout/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useRafTimeout from '../index'; interface ParamsObj { fn: (...arg: any) => any; delay: number | undefined; } const setUp = ({ fn, delay }: ParamsObj) => renderHook(() => useRafTimeout(fn, delay)); const FRAME_TIME = 16.7; describe('useRafTimeout', () => ...
366
0
petrpan-code/alibaba/hooks/packages/hooks/src/useReactive
petrpan-code/alibaba/hooks/packages/hooks/src/useReactive/__tests__/index.test.tsx
import { fireEvent, render, renderHook, act } from '@testing-library/react'; import React from 'react'; import useReactive from '../'; const Demo = () => { const state: { count: number; val: any; foo?: string; arr: number[]; } = useReactive({ count: 0, val: { val1: { val2: '',...
373
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/index.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); describe('useRequest', () => { beforeAll(() => { jest.useFakeTimers(); }); ...
374
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/useAutoRunPlugin.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; describe('useAutoRunPlugin', () => { jest.useFakeTimers(); const setUp = (service, options) => renderHook((o) => useRequest(service, o || options)); let ho...
375
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/useCachePlugin.test.tsx
import { act, renderHook, waitFor } from '@testing-library/react'; import { render } from '@testing-library/react'; import useRequest, { clearCache } from '../index'; import { request } from '../../utils/testingHelpers'; import React, { useState } from 'react'; import 'jest-localstorage-mock'; describe('useCachePlugin...
376
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/useDebouncePlugin.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; describe('useDebouncePlugin', () => { const setUp = (service, options) => renderHook((o) => useRequest(service, o || options)); let hook; it('useDebouncePlu...
377
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/useLoadingDelayPlugin.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import type { RenderHookResult } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; describe('useLoadingDelayPlugin', () => { jest.useFakeTimers(); const setUp = (service, option...
378
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/usePollingPlugin.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; describe('usePollingPlugin', () => { jest.useFakeTimers(); const setUp = (service, options) => renderHook((o) => useRequest(service, o || options)); let ho...
379
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/useRefreshOnWindowFocusPlugin.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import { fireEvent } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; describe('useRefreshOnWindowFocusPlugin', () => { jest.useFakeTimers(); const setUp = (service, options) =...
380
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/useRetryPlugin.test.ts
import { act, renderHook, waitFor } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; describe('useRetryPlugin', () => { jest.useFakeTimers(); const setUp = (service, options) => renderHook((o) => useRequest(service, o || options)); let hook...
381
0
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest
petrpan-code/alibaba/hooks/packages/hooks/src/useRequest/__tests__/useThrottlePlugin.test.ts
import { act, renderHook } from '@testing-library/react'; import useRequest from '../index'; import { request } from '../../utils/testingHelpers'; describe('useThrottlePlugin', () => { jest.useFakeTimers(); const setUp = (service, options) => renderHook((o) => useRequest(service, o || options)); let hook; it...
454
0
petrpan-code/alibaba/hooks/packages/hooks/src/useResetState
petrpan-code/alibaba/hooks/packages/hooks/src/useResetState/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useResetState from '../index'; describe('useResetState', () => { const setUp = <S>(initialState: S) => renderHook(() => { const [state, setState, resetState] = useResetState<S>(initialState); return { state, setState, ...
459
0
petrpan-code/alibaba/hooks/packages/hooks/src/useResponsive
petrpan-code/alibaba/hooks/packages/hooks/src/useResponsive/__tests__/index.test.ts
import { renderHook, act } from '../../utils/tests'; import { useResponsive } from '../'; describe('useResponsive', () => { function changeWidth(width: number) { act(() => { (global as any).innerWidth = width; (global as any).dispatchEvent(new Event('resize')); }); } changeWidth(1024); con...
460
0
petrpan-code/alibaba/hooks/packages/hooks/src/useResponsive/__tests__
petrpan-code/alibaba/hooks/packages/hooks/src/useResponsive/__tests__/__snapshots__/index.test.ts.snap
// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`useResponsive should response to window width changes 1`] = ` { "lg": true, "md": true, "sm": true, "xl": false, "xs": true, } `; exports[`useResponsive should response to window width changes 2`] = ` { "lg": false, "md": false, "sm": false, "xl": ...
465
0
petrpan-code/alibaba/hooks/packages/hooks/src/useSafeState
petrpan-code/alibaba/hooks/packages/hooks/src/useSafeState/__tests__/index.test.ts
import { act, renderHook, RenderHookResult } from '@testing-library/react'; import useSafeState from '../index'; describe('useSetState', () => { const setUp = (initialValue: any) => renderHook(() => { const [state, setState] = useSafeState(initialValue); return { state, setState, ...
470
0
petrpan-code/alibaba/hooks/packages/hooks/src/useScroll
petrpan-code/alibaba/hooks/packages/hooks/src/useScroll/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useScroll from '../index'; describe('useScroll', () => { it('document body', () => { const hook = renderHook(() => useScroll(document)); expect(hook.result.current).toBeUndefined(); }); });
477
0
petrpan-code/alibaba/hooks/packages/hooks/src/useSelections
petrpan-code/alibaba/hooks/packages/hooks/src/useSelections/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useSelections from '../index'; const data = [1, 2, 3]; const setup = <T>(items: T[], defaultSelected?: T[]) => { return renderHook(() => useSelections(items, defaultSelected)); }; describe('useSelections', () => { it('defaultSelected should work co...
482
0
petrpan-code/alibaba/hooks/packages/hooks/src/useSessionStorageState
petrpan-code/alibaba/hooks/packages/hooks/src/useSessionStorageState/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useSessionStorageState from '../index'; describe('useSessionStorageState', () => { const setUp = <T>(key: string, value: T) => renderHook(() => { const [state, setState] = useSessionStorageState<T>(key, { defaultValue: value }); return ...
486
0
petrpan-code/alibaba/hooks/packages/hooks/src/useSet
petrpan-code/alibaba/hooks/packages/hooks/src/useSet/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useSet from '../index'; const setUp = <K>(initialSet?: Iterable<K>) => renderHook(() => useSet(initialSet)); describe('useSet', () => { it('should init set and utils', () => { const { result } = setUp([1, 2]); const [set, utils] = result.curre...
491
0
petrpan-code/alibaba/hooks/packages/hooks/src/useSetState
petrpan-code/alibaba/hooks/packages/hooks/src/useSetState/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useSetState from '../index'; describe('useSetState', () => { const setUp = <T extends object>(initialValue: T) => renderHook(() => { const [state, setState] = useSetState<T>(initialValue); return { state, setState, ...
497
0
petrpan-code/alibaba/hooks/packages/hooks/src/useSize
petrpan-code/alibaba/hooks/packages/hooks/src/useSize/__tests__/index.test.tsx
import React, { useRef } from 'react'; import { renderHook, act, render, screen } from '@testing-library/react'; import useSize from '../index'; let callback; jest.mock('resize-observer-polyfill', () => { return jest.fn().mockImplementation((cb) => { callback = cb; return { observe: () => {}, dis...
503
0
petrpan-code/alibaba/hooks/packages/hooks/src/useTextSelection
petrpan-code/alibaba/hooks/packages/hooks/src/useTextSelection/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useTextSelection from '../index'; // test about Resize Observer see https://github.com/que-etc/resize-observer-polyfill/tree/master/tests describe('useTextSelection', () => { function moveMouse(x: number, y: number) { act(() => { document.dis...
511
0
petrpan-code/alibaba/hooks/packages/hooks/src/useThrottle
petrpan-code/alibaba/hooks/packages/hooks/src/useThrottle/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useThrottle from '../index'; import { sleep } from '../../utils/testingHelpers'; let hook; describe('useThrottle', () => { it('default useThrottle should work', async () => { let mountedState = 1; act(() => { hook = renderHook(() => useT...
516
0
petrpan-code/alibaba/hooks/packages/hooks/src/useThrottleEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useThrottleEffect/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useThrottleEffect from '../index'; import { sleep } from '../../utils/testingHelpers'; let hook; describe('useThrottleEffect', () => { it('useThrottleEffect should work', async () => { const mockEffect = jest.fn(() => {}); const mockCleanUp = ...
521
0
petrpan-code/alibaba/hooks/packages/hooks/src/useThrottleFn
petrpan-code/alibaba/hooks/packages/hooks/src/useThrottleFn/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useThrottleFn from '../index'; import { sleep } from '../../utils/testingHelpers'; interface ParamsObj { fn: (...arg: any) => any; deps?: any[]; wait: number; } const setUp = ({ fn, wait }: ParamsObj) => renderHook(() => useThrottleFn(fn, { wait }...
526
0
petrpan-code/alibaba/hooks/packages/hooks/src/useTimeout
petrpan-code/alibaba/hooks/packages/hooks/src/useTimeout/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useTimeout from '../index'; interface ParamsObj { fn: (...arg: any) => any; delay: number | undefined; } const setUp = ({ fn, delay }: ParamsObj) => renderHook(() => useTimeout(fn, delay)); describe('useTimeout', () => { jest.useFakeTimers(); jest.s...
532
0
petrpan-code/alibaba/hooks/packages/hooks/src/useTitle
petrpan-code/alibaba/hooks/packages/hooks/src/useTitle/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useTitle from '../index'; describe('useTitle', () => { it('should update document title', () => { const hook = renderHook((props) => useTitle(props), { initialProps: 'Current Page Title' }); expect(document.title).toBe('Current Page Title'); ...
537
0
petrpan-code/alibaba/hooks/packages/hooks/src/useToggle
petrpan-code/alibaba/hooks/packages/hooks/src/useToggle/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useToggle from '../index'; const callToggle = (hook: any) => { act(() => { hook.result.current[1].toggle(); }); }; describe('useToggle', () => { it('test on init', async () => { const hook = renderHook(() => useToggle()); expect(hook.r...
543
0
petrpan-code/alibaba/hooks/packages/hooks/src/useTrackedEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useTrackedEffect/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useTrackedEffect from '../index'; describe('useTrackedEffect', () => { //We use a array to store which dependency has changed let changedDepIndexes = []; let prevDependencies = []; let currentDependencies = []; const mockEffectCleanup = jest.fn(); ...
548
0
petrpan-code/alibaba/hooks/packages/hooks/src/useUnmount
petrpan-code/alibaba/hooks/packages/hooks/src/useUnmount/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useUnmount from '../index'; describe('useUnmount', () => { it('useUnmount should work', async () => { const fn = jest.fn(); const hook = renderHook(() => useUnmount(fn)); expect(fn).toBeCalledTimes(0); hook.rerender(); expect(fn).toBeCall...
553
0
petrpan-code/alibaba/hooks/packages/hooks/src/useUnmountedRef
petrpan-code/alibaba/hooks/packages/hooks/src/useUnmountedRef/__tests__/index.test.ts
import { renderHook } from '../../utils/tests'; import useUnmountedRef from '../index'; describe('useUnmountedRef', () => { it('should work', async () => { const hook = renderHook(() => useUnmountedRef()); expect(hook.result.current.current).toBe(false); hook.rerender(); expect(hook.result.current.cu...
558
0
petrpan-code/alibaba/hooks/packages/hooks/src/useUpdate
petrpan-code/alibaba/hooks/packages/hooks/src/useUpdate/__tests__/index.test.ts
import { renderHook, act } from '@testing-library/react'; import useUpdate from '..'; import useMemoizedFn from '../../useMemoizedFn'; describe('useUpdate', () => { it('should update', () => { let count = 0; const hooks = renderHook(() => { const update = useUpdate(); return { update, ...
563
0
petrpan-code/alibaba/hooks/packages/hooks/src/useUpdateEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useUpdateEffect/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useUpdateEffect from '../index'; describe('useUpdateEffect', () => { it('test on mounted', async () => { let mountedState = 1; const hook = renderHook(() => useUpdateEffect(() => { mountedState = 2; }), ); expect(mountedS...
568
0
petrpan-code/alibaba/hooks/packages/hooks/src/useUpdateLayoutEffect
petrpan-code/alibaba/hooks/packages/hooks/src/useUpdateLayoutEffect/__tests__/index.test.ts
import { renderHook } from '@testing-library/react'; import useUpdateLayoutEffect from '../index'; describe('useUpdateLayoutEffect', () => { it('test on mounted', async () => { let mountedState = 1; const hook = renderHook(() => useUpdateLayoutEffect(() => { mountedState = 2; }), ); ...
573
0
petrpan-code/alibaba/hooks/packages/hooks/src/useVirtualList
petrpan-code/alibaba/hooks/packages/hooks/src/useVirtualList/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import useVirtualList, { Options } from '../index'; describe('useVirtualList', () => { describe('virtual list render', () => { let hook: any; let container: HTMLDivElement; let wrapper: HTMLDivElement; beforeEach(() => { container = doc...
579
0
petrpan-code/alibaba/hooks/packages/hooks/src/useWebSocket
petrpan-code/alibaba/hooks/packages/hooks/src/useWebSocket/__tests__/index.test.ts
import { act, renderHook } from '@testing-library/react'; import WS from 'jest-websocket-mock'; import { sleep } from '../../utils/testingHelpers'; import useWebSocket, { ReadyState } from '../index'; const promise: Promise<void> = new Promise((resolve) => resolve()); const wsUrl = 'ws://localhost:9999'; describe('us...