Skip to content

Commit

Permalink
fix: 修复useAntdTable在manual=true时,初始化仍然发起请求的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-try committed Dec 31, 2024
1 parent c7bb04c commit f1421f6
Show file tree
Hide file tree
Showing 62 changed files with 125 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { useEffect, useLayoutEffect, useState } from 'react';
import { renderHook } from '@testing-library/react';
import { useEffect, useLayoutEffect, useState, act } from 'react';
import { createDeepCompareEffect } from '../index';

describe('createDeepCompareEffect', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import type { Options } from '../index';
import { createUseStorageState } from '../index';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useAntdTable/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import { act } from 'react';
import { sleep } from '../../utils/testingHelpers';
import useAntdTable from '../index';

Expand Down
4 changes: 3 additions & 1 deletion packages/hooks/src/useAntdTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ const useAntdTable = <TData extends Data, TParams extends Params>(
if (ready) {
allFormDataRef.current = defaultParams?.[1] || {};
restoreForm();
_submit(defaultParams?.[0]);
if(!manual) {
_submit(defaultParams?.[0]);
}
}
}, []);

Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useAsyncEffect/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import useAsyncEffect from '../index';
import { useState } from 'react';
import { useState, act } from 'react';
import { sleep } from '../../utils/testingHelpers';

describe('useAsyncEffect', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useBoolean/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useBoolean from '../index';

const setUp = (defaultValue?: boolean) => renderHook(() => useBoolean(defaultValue));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useControllableValue, { Options, Props } from '../index';

describe('useControllableValue', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useCookieState/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useCookieState from '../index';
import type { Options } from '../index';
import Cookies from 'js-cookie';
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useCountDown/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import type { Options } from '../index';
import useCountDown from '../index';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useCounter/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useCounter, { Options } from '../index';

const setUp = (init?: number, options?: Options) => renderHook(() => useCounter(init, options));
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useCreation/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { useState } from 'react';
import useCreation from '../index';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useDebounce/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useDebounce from '../index';
import { sleep } from '../../utils/testingHelpers';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useDebounceEffect/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useDebounceEffect from '../index';
import { sleep } from '../../utils/testingHelpers';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useDebounceFn/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { sleep } from '../../utils/testingHelpers';
import useDebounceFn from '../index';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { useState } from 'react';
import useDeepCompareEffect from '../index';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { useState } from 'react';
import useDeepCompareLayoutEffect from '../index';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useDocumentVisibility from '../index';
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';

const mockIsBrowser = jest.fn();
const mockDocumentVisibilityState = jest.spyOn(document, 'visibilityState', 'get');
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useDynamicList/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useDynamicList from '../index';

describe('useDynamicList', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useEventEmitter/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { useState } from 'react';
import useEventEmitter from '../index';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useEventTarget/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useEventTarget from '../index';

describe('useEventTarget', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useExternal/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useExternal, { Options } from '../index';
import { fireEvent } from '@testing-library/react';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useFullscreen/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useFullscreen from '../index';
import type { Options } from '../index';
import type { BasicTarget } from '../../utils/domTarget';
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useFusionTable/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useFusionTable from '../index';
import { sleep } from '../../utils/testingHelpers';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useGetState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useGetState from '../index';

describe('useGetState', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useHistoryTravel/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useHistoryTravel from '../index';

describe('useHistoryTravel', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useHover/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// write your test cases here
import React from 'react';
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { render, fireEvent } from '@testing-library/react';
import useHover from '../index';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useInViewport/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useInViewport from '../index';

const targetEl = document.createElement('div');
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useInfiniteScroll/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useInfiniteScroll from '..';
import type { Data, Service, InfiniteScrollOptions } from '../types';
import { sleep } from '../../utils/testingHelpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import type { Options } from '../../createUseStorageState';
import useLocalStorageState from '../index';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useLockFn/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { useRef, useCallback, useState } from 'react';
import useLockFn from '../index';
import { sleep } from '../../utils/testingHelpers';
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useMap/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useMap from '../index';

const setup = (initialMap?: Iterable<[any, any]>) => renderHook(() => useMap(initialMap));
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useMemoizedFn/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { useState } from 'react';
import useMemoizedFn from '../';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useNetwork/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useNetwork from '../index';
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';

describe('useNetwork', () => {
it('toggle network state', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useRafState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useRafState from '../index';

describe('useRafState', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useReactive/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fireEvent, render, renderHook, act } from '@testing-library/react';
import React from 'react';
import { fireEvent, render, renderHook } from '@testing-library/react';
import React, { act } from 'react';
import useReactive from '../';

const Demo = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import { act } from 'react';
import useRequest from '../index';
import { request } from '../../utils/testingHelpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import { render } from '@testing-library/react';
import { act } from 'react';
import useRequest, { clearCache } from '../index';
import { request } from '../../utils/testingHelpers';
import React, { useState } from 'react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import { act } from 'react';
import useRequest from '../index';
import { request } from '../../utils/testingHelpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import type { RenderHookResult } from '@testing-library/react';
import { act } from 'react';
import useRequest from '../index';
import { request } from '../../utils/testingHelpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import { act } from 'react';
import useRequest from '../index';
import { request } from '../../utils/testingHelpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { fireEvent } from '@testing-library/react';
import { fireEvent , renderHook, waitFor } from '@testing-library/react';
import { act } from 'react';
import useRequest from '../index';
import { request } from '../../utils/testingHelpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook, waitFor } from '@testing-library/react';
import { renderHook, waitFor } from '@testing-library/react';
import { act } from 'react';
import useRequest from '../index';
import { request } from '../../utils/testingHelpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useRequest from '../index';
import { request } from '../../utils/testingHelpers';

Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useResetState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useResetState from '../index';

describe('useResetState', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useResponsive/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '../../utils/tests';
import { renderHook } from '../../utils/tests';
import { act } from 'react';
import useResponsive from '../';

describe('useResponsive', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useSafeState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook, RenderHookResult } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useSafeState from '../index';

describe('useSetState', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useSelections/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import { useState } from 'react';
import useSelections from '../index';
import type { Options } from '../index';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useSessionStorageState from '../index';

describe('useSessionStorageState', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useSet/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useSet from '../index';

const setUp = <K>(initialSet?: Iterable<K>) => renderHook(() => useSet(initialSet));
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useSetState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useSetState from '../index';

describe('useSetState', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useSize/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef } from 'react';
import { renderHook, act, render, screen } from '@testing-library/react';
import React, { useRef ,act } from 'react';
import { renderHook, render, screen } from '@testing-library/react';
import useSize from '../index';

let callback;
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useTextSelection/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { renderHook, act } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useTextSelection from '../index';

// test about Resize Observer see https://github.com/que-etc/resize-observer-polyfill/tree/master/tests
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useTheme/__test__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useTheme from '../index';

describe('useTheme', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/src/useThrottle/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, renderHook } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { act } from 'react';
import useThrottle from '../index';
import { sleep } from '../../utils/testingHelpers';

Expand Down
Loading

0 comments on commit f1421f6

Please sign in to comment.