Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add exports modules test #1716

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/hooks/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as ahooks from '..';

describe('ahooks', () => {
test('exports modules should be defined', () => {
Object.keys(ahooks).forEach((module) => {
expect(ahooks[module]).toBeDefined();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { useEffect, useLayoutEffect, useState } from 'react';
import { createDeepCompareEffect } from '../index';

describe('createDeepCompareEffect', () => {
it('should be defined', () => {
expect(createDeepCompareEffect).toBeDefined();
});

it('should work for useEffect', async () => {
const useDeepCompareEffect = createDeepCompareEffect(useEffect);

Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/createUpdateEffect/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { useEffect, useLayoutEffect } from 'react';
import { createUpdateEffect } from '../index';

describe('createUpdateEffect', () => {
it('should be defined', () => {
expect(createUpdateEffect).toBeDefined();
});

it('should work for useEffect', () => {
const useUpdateEffect = createUpdateEffect(useEffect);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ describe('useStorageState', () => {
);
};

it('should be defined', () => {
expect(createUseStorageState);
});

it('should get defaultValue for a given key', () => {
const hook = setUp({ key: 'key1', defaultValue: 'value1' });
expect(hook.result.current.state).toEqual('value1');
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useAntdTable/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ describe('useAntdTable', () => {
// hook?.unmount();
// });

it('should be defined', () => {
expect(useAntdTable).toBeDefined();
});

it('should fetch after first render', async () => {
queryArgs = undefined;
form.resetFields();
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useAsyncEffect/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { useState } from 'react';
import { sleep } from '../../utils/testingHelpers';

describe('useAsyncEffect', () => {
it('should be defined', () => {
expect(useAsyncEffect).toBeDefined();
});

it('should work without clean up', async () => {
const hook = renderHook(() => {
const [x, setX] = useState(0);
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useBoolean/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import useBoolean from '../index';
const setUp = (defaultValue?: boolean) => renderHook(() => useBoolean(defaultValue));

describe('useBoolean', () => {
it('should be defined', () => {
expect(useBoolean).toBeDefined();
});

it('test on methods', async () => {
const { result } = setUp();
expect(result.current[0]).toBe(false);
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useClickAway/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { renderHook } from '@testing-library/react-hooks';
import useClickAway from '../index';

describe('useClickAway', () => {
it('should be defined', () => {
expect(useClickAway).toBeDefined();
});

let container: HTMLDivElement;
let container1: HTMLDivElement;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { act, renderHook } from '@testing-library/react-hooks';
import useControllableValue, { Options, Props } from '../index';

describe('useControllableValue', () => {
it('should be defined', () => {
expect(useControllableValue).toBeDefined();
});

const setUp = (props?: Props, options?: Options<any>): any =>
renderHook(() => useControllableValue(props, options));

Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useCookieState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import useCookieState, { Options } from '../index';
import Cookies from 'js-cookie';

describe('useCookieState', () => {
it('should be defined', () => {
expect(useCookieState).toBeDefined();
});

const setUp = (key: string, options: Options) =>
renderHook(() => {
const [state, setState] = useCookieState(key, options);
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useCreation/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { useState } from 'react';
import useCreation from '../index';

describe('useCreation', () => {
it('should be defined', () => {
expect(useCreation).toBeDefined();
});

class Foo {
constructor() {
this.data = Math.random();
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useDebounce/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import useDebounce from '../index';
import { sleep } from '../../utils/testingHelpers';

describe('useDebounce', () => {
it('should be defined', () => {
expect(useDebounce).toBeDefined();
});

it('useDebounce wait:200ms', async () => {
let mountedState = 0;
const { result, rerender } = renderHook(() => useDebounce(mountedState, { wait: 200 }));
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useDebounceEffect/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ interface ParamsObj {
let hook: RenderHookResult<ParamsObj, any>;

describe('useDebounceEffect', () => {
it('should be defined', () => {
expect(useDebounceEffect).toBeDefined();
});

it('useDebounceEffect should work', async () => {
let mountedState = 1;
const mockEffect = jest.fn(() => {});
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useDebounceFn/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ const setUp = ({ fn, wait }: ParamsObj) => renderHook(() => useDebounceFn(fn, {
let hook: RenderHookResult<ParamsObj, ReturnType<typeof useDebounceFn>>;

describe('useDebounceFn', () => {
it('should be defined', () => {
expect(useDebounceFn).toBeDefined();
});

it('run, cancel and flush should work', async () => {
act(() => {
hook = setUp({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { useState } from 'react';
import useDeepCompareEffect from '../index';

describe('useDeepCompareEffect', () => {
it('should be defined', () => {
expect(useDeepCompareEffect).toBeDefined();
});

it('test deep compare', async () => {
const hook = renderHook(() => {
const [x, setX] = useState(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { useState } from 'react';
import useDeepCompareLayoutEffect from '../index';

describe('useDeepCompareLayoutEffect', () => {
it('should be defined', () => {
expect(useDeepCompareLayoutEffect).toBeDefined();
});

it('test deep compare', async () => {
const hook = renderHook(() => {
const [x, setX] = useState(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ afterAll(() => {
});

describe('useDocumentVisibility', () => {
it('should be defined', () => {
expect(useDocumentVisibility).toBeDefined();
});

it('isBrowser effect corrent', async () => {
mockDocumentVisibilityState.mockReturnValue('hidden');
// Object.defineProperty(document, 'visibilityState', { value: 'hidden', writable: true });
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useDrag/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ const mockTarget = {
};

describe('useDrag', () => {
it('should be defined', () => {
expect(useDrag).toBeDefined();
});

it('should add/remove listener on mount/unmount', () => {
const { unmount } = setup(1, mockTarget as any);
expect(mockTarget.addEventListener).toBeCalled();
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useDrop/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ const mockEvent = {
};

describe('useDrop', () => {
it('should be defined', () => {
expect(useDrop).toBeDefined();
});

it(`should not work when target don't support addEventListener method`, () => {
const originAddEventListener = mockTarget.addEventListener;
Object.defineProperty(mockTarget, 'addEventListener', {
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useDynamicList/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { renderHook, act } from '@testing-library/react-hooks';
import useDynamicList from '../index';

describe('useDynamicList', () => {
it('should be defined', () => {
expect(useDynamicList).toBeDefined();
});

const setUp = (props: any): any => renderHook(() => useDynamicList(props));

it('getKey should work', () => {
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useEventEmitter/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { useState } from 'react';
import useEventEmitter from '../index';

describe('useEventEmitter', () => {
it('should be defined', () => {
expect(useEventEmitter).toBeDefined();
});

const setUp = (): any =>
renderHook(() => {
const event$ = useEventEmitter<number>();
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useEventListener/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { renderHook } from '@testing-library/react-hooks';
import useEventListener from '../index';

describe('useEventListener', () => {
it('should be defined', () => {
expect(useEventListener).toBeDefined();
});

let container: HTMLDivElement;

beforeEach(() => {
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useEventTarget/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { renderHook, act } from '@testing-library/react-hooks';
import useEventTarget from '../index';

describe('useEventTarget', () => {
it('should be defined', () => {
expect(useEventTarget).toBeDefined();
});

it('should work without initial value', async () => {
const hook = renderHook(() => useEventTarget());
expect(hook.result.current[0]).toEqual(undefined);
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useExternal/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ describe('useExternal', () => {
document.head.innerHTML = '';
});

it('should be defined', () => {
expect(useExternal).toBeDefined();
});

it('should load a script', () => {
const path = 'https://ahooks.js.org/useExternal/test-external-script.js';
const { result } = setup(path, {
Expand Down
5 changes: 0 additions & 5 deletions packages/hooks/src/useFavicon/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ const App: React.FC = () => {
};

describe.only('useFavicon Hook', () => {
it('should be defined as function', () => {
expect(useFavicon).toBeDefined();
expect(typeof useFavicon).toBe('function');
});

it('should toggle favicon when URL changed', () => {
const wrapper = mount(<App />);
const currentFaviconURL = wrapper.find('span').at(0);
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useFocusWithin/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const setup = (options?: Options) => {
};

describe('useFocusWithin', () => {
it('should be defined', () => {
expect(useFocusWithin).toBeDefined();
});

it('should call onFocus/onBlur', () => {
const onFocus = jest.fn();
const onBlur = jest.fn();
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useFullscreen/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ describe('useFullscreen', () => {
jest.resetAllMocks();
});

it('should be defined', () => {
expect(useFullscreen).toBeDefined();
});

it('enterFullscreen/exitFullscreen should be work', () => {
const { result } = setup(targetEl);
const { enterFullscreen, exitFullscreen } = result.current[1];
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useFusionTable/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ describe('useFusionTable', () => {
jest.useRealTimers();
});

it('should be defined', () => {
expect(useFusionTable).toBeDefined();
});

it('should get table & pagination props', async () => {
const { result } = setup(getTableData);
await act(async () => {
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useGetState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { act, renderHook } from '@testing-library/react-hooks';
import useGetState from '../index';

describe('useGetState', () => {
it('should be defined', () => {
expect(useGetState).toBeDefined();
});

const setUp = <T>(initialValue: T) =>
renderHook(() => {
const [state, setState, getState] = useGetState<T>(initialValue);
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useHistoryTravel/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { renderHook, act } from '@testing-library/react-hooks';
import useHistoryTravel from '../index';

describe('useHistoryTravel', () => {
it('should be defined', () => {
expect(useHistoryTravel).toBeDefined();
});

it('should work without initial value', async () => {
const hook = renderHook(() => useHistoryTravel());
expect(hook.result.current.value).toEqual(undefined);
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useHover/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { render, fireEvent } from '@testing-library/react';
import useHover from '../index';

describe('useHover', () => {
it('should be defined', () => {
expect(useHover).toBeDefined();
});

it('should work', () => {
const { getByText } = render(<button>Hover</button>);
let trigger = 0;
Expand Down
4 changes: 0 additions & 4 deletions packages/hooks/src/useInViewport/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ const mockIntersectionObserver = jest.fn().mockReturnValue({
window.IntersectionObserver = mockIntersectionObserver;

describe('useInViewport', () => {
it('should be defined', () => {
expect(useInViewport).toBeDefined();
});

it('should work when target is in viewport', async () => {
const { result } = renderHook(() => useInViewport(targetEl));
const calls = mockIntersectionObserver.mock.calls;
Expand Down
Loading