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: replace toEqual with toBe for boolean results #2045

Merged
merged 2 commits into from
Feb 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/hooks/src/useAntdTable/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('useAntdTable', () => {
hook = setUp(asyncFn, {});
});

expect(hook.result.current.tableProps.loading).toEqual(false);
expect(hook.result.current.tableProps.loading).toBe(false);
expect(hook.result.current.tableProps.pagination.current).toEqual(1);
expect(hook.result.current.tableProps.pagination.pageSize).toEqual(10);
await waitFor(() => expect(hook.result.current.tableProps.pagination.total).toEqual(20));
Expand All @@ -103,7 +103,7 @@ describe('useAntdTable', () => {
});
});
const { search } = hook.result.current;
expect(hook.result.current.tableProps.loading).toEqual(false);
expect(hook.result.current.tableProps.loading).toBe(false);
await waitFor(() => expect(queryArgs.current).toEqual(2));
expect(queryArgs.pageSize).toEqual(10);
expect(queryArgs.name).toEqual('hello');
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('useAntdTable', () => {
});

const { search } = hook.result.current;
expect(hook.result.current.tableProps.loading).toEqual(false);
expect(hook.result.current.tableProps.loading).toBe(false);
await waitFor(() => expect(queryArgs.current).toEqual(2));
expect(queryArgs.pageSize).toEqual(10);
expect(queryArgs.name).toEqual('hello');
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('useAntdTable', () => {
hook = setUp(asyncFn, { form: v3Form });
});
const { search } = hook.result.current;
expect(hook.result.current.tableProps.loading).toEqual(false);
expect(hook.result.current.tableProps.loading).toBe(false);
await waitFor(() => expect(queryArgs.current).toEqual(1));
expect(queryArgs.pageSize).toEqual(10);
expect(queryArgs.name).toEqual('default name');
Expand Down
12 changes: 6 additions & 6 deletions packages/hooks/src/useLocalStorageState/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ describe('useLocalStorageState', () => {
it('should support boolean', () => {
const LOCAL_STORAGE_KEY = 'test-boolean-key';
const hook = setUp(LOCAL_STORAGE_KEY, true);
expect(hook.result.current.state).toEqual(true);
expect(hook.result.current.state).toBe(true);
act(() => {
hook.result.current.setState(false);
});
expect(hook.result.current.state).toEqual(false);
expect(hook.result.current.state).toBe(false);
const anotherHook = setUp(LOCAL_STORAGE_KEY, true);
expect(anotherHook.result.current.state).toEqual(false);
expect(anotherHook.result.current.state).toBe(false);
act(() => {
anotherHook.result.current.setState(true);
});
expect(anotherHook.result.current.state).toEqual(true);
expect(hook.result.current.state).toEqual(false);
expect(anotherHook.result.current.state).toBe(true);
expect(hook.result.current.state).toBe(false);
});

it('should support null', () => {
const LOCAL_STORAGE_KEY = 'test-boolean-key-with-null';
const hook = setUp<boolean | null>(LOCAL_STORAGE_KEY, false);
expect(hook.result.current.state).toEqual(false);
expect(hook.result.current.state).toBe(false);
act(() => {
hook.result.current.setState(null);
});
Expand Down
30 changes: 15 additions & 15 deletions packages/hooks/src/usePagination/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ describe('usePagination', () => {
act(() => {
hook = setUp(asyncFn, {});
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(1);
expect(queryArgs.pageSize).toEqual(10);
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));

expect(hook.result.current.pagination.current).toEqual(1);
expect(hook.result.current.pagination.pageSize).toEqual(10);
Expand All @@ -43,31 +43,31 @@ describe('usePagination', () => {
act(() => {
hook = setUp(asyncFn, {});
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(1);
expect(queryArgs.pageSize).toEqual(10);
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));

act(() => {
hook.result.current.pagination.changeCurrent(2);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(2);
expect(queryArgs.pageSize).toEqual(10);
await waitFor(() => expect(hook.result.current.pagination.current).toEqual(2));

act(() => {
hook.result.current.pagination.changeCurrent(10);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(6);
expect(queryArgs.pageSize).toEqual(10);
await waitFor(() => expect(hook.result.current.pagination.current).toEqual(6));

act(() => {
hook.result.current.pagination.changePageSize(20);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(3);
expect(queryArgs.pageSize).toEqual(20);
await waitFor(() => expect(hook.result.current.pagination.current).toEqual(3));
Expand All @@ -77,7 +77,7 @@ describe('usePagination', () => {
act(() => {
hook.result.current.pagination.onChange(2, 10);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(2);
expect(queryArgs.pageSize).toEqual(10);
await waitFor(() => expect(hook.result.current.pagination.current).toEqual(2));
Expand All @@ -93,15 +93,15 @@ describe('usePagination', () => {
refreshDeps: [dep],
});
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(1);
expect(queryArgs.pageSize).toEqual(10);
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));

act(() => {
hook.result.current.pagination.onChange(3, 20);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
await waitFor(() => expect(hook.result.current.pagination.current).toEqual(3));
expect(hook.result.current.pagination.pageSize).toEqual(20);

Expand All @@ -110,7 +110,7 @@ describe('usePagination', () => {
refreshDeps: [dep],
});

expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(1);
expect(queryArgs.pageSize).toEqual(20);
await waitFor(() => expect(hook.result.current.pagination.current).toEqual(1));
Expand All @@ -125,10 +125,10 @@ describe('usePagination', () => {
defaultCurrent: 2,
});
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(2);
expect(queryArgs.pageSize).toEqual(5);
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));

expect(hook.result.current.pagination.current).toEqual(2);
expect(hook.result.current.pagination.pageSize).toEqual(5);
Expand All @@ -138,7 +138,7 @@ describe('usePagination', () => {
act(() => {
hook.result.current.pagination.changeCurrent(3);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(queryArgs.current).toEqual(3);
expect(queryArgs.pageSize).toEqual(5);
await waitFor(() => expect(hook.result.current.pagination.current).toEqual(3));
Expand Down
30 changes: 15 additions & 15 deletions packages/hooks/src/useRequest/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ describe('useRequest', () => {
onFinally: finallyCallback,
});
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);
expect(value).toEqual('before');
expect(success).toEqual(undefined);

act(() => {
jest.runAllTimers();
});
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));
expect(success).toEqual('success');
expect(hook.result.current.data).toEqual('success');
expect(value).toEqual('finally');
Expand All @@ -53,26 +53,26 @@ describe('useRequest', () => {
act(() => {
hook.result.current.run(0);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);

act(() => {
jest.runAllTimers();
});
await waitFor(() => expect(hook.result.current.error).toEqual(new Error('fail')));
expect(hook.result.current.loading).toEqual(false);
expect(hook.result.current.loading).toBe(false);
expect(errorCallback).toHaveBeenCalledTimes(1);

//manual run success
act(() => {
hook.result.current.run(1);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);

act(() => {
jest.runAllTimers();
});
expect(hook.result.current.data).toEqual('success');
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));
expect(errorCallback).toHaveBeenCalledTimes(1);
hook.unmount();

Expand All @@ -83,13 +83,13 @@ describe('useRequest', () => {
onError: errorCallback,
});
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);

act(() => {
jest.runAllTimers();
});
await waitFor(() => expect(hook.result.current.error).toEqual(new Error('fail')));
expect(hook.result.current.loading).toEqual(false);
expect(hook.result.current.loading).toBe(false);
expect(errorCallback).toHaveBeenCalledTimes(2);
hook.unmount();
});
Expand All @@ -100,26 +100,26 @@ describe('useRequest', () => {
manual: true,
});
});
expect(hook.result.current.loading).toEqual(false);
expect(hook.result.current.loading).toBe(false);
act(() => {
hook.result.current.run(1);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);

act(() => {
jest.runAllTimers();
});
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));
expect(hook.result.current.data).toEqual('success');
act(() => {
hook.result.current.run(0);
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);

act(() => {
jest.runAllTimers();
});
await waitFor(() => expect(hook.result.current.loading).toEqual(false));
await waitFor(() => expect(hook.result.current.loading).toBe(false));
expect(hook.result.current.error).toEqual(new Error('fail'));
hook.unmount();
});
Expand Down Expand Up @@ -192,14 +192,14 @@ describe('useRequest', () => {
defaultParams: [1, 2, 3],
});
});
expect(hook.result.current.loading).toEqual(true);
expect(hook.result.current.loading).toBe(true);

act(() => {
jest.runAllTimers();
});
expect(hook.result.current.params).toEqual([1, 2, 3]);
await waitFor(() => expect(hook.result.current.data).toEqual('success'));
expect(hook.result.current.loading).toEqual(false);
expect(hook.result.current.loading).toBe(false);
hook.unmount();
});
});