Skip to content

Commit

Permalink
test: remove @testing-library/react-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
wangcch committed Oct 20, 2023
1 parent 3a8f8f8 commit e7e888a
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 230 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"react": ">=16.8.2"
},
"devDependencies": {
"@testing-library/react": "^13.2.0",
"@testing-library/react-hooks": "^8.0.0",
"@testing-library/react": "^14.0.0",
"@types/jest": "^27.4.0",
"@types/react": "^18.0.9",
"@types/react-dom": "^18.0.3",
Expand Down
34 changes: 18 additions & 16 deletions tests/useRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,44 @@ describe("useRequest", () => {
useRequest(() => ({ url: "/users", method: "GET" })),
);

void act(() => {
void result.current[0]().ready();
act(() => {
result.current[0]()
.ready()
.catch(() => undefined);
expect(result.current[1].hasPending).toBeFalsy();
});

unmount();
expect(result.current[1].hasPending).toBeTruthy();
});

it("clear", async () => {
const { result, unmount, waitForNextUpdate } = renderHook(() =>
it("clear", () => {
const { result, unmount } = renderHook(() =>
useRequest(() => ({ url: "/users", method: "GET" })),
);

void act(() => {
void result.current[0]()
act(() => {
result.current[0]()
.ready()
.catch((e) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
expect(e.message).toStrictEqual("clear-messgae");
});
});

void act(() => {
void result.current[0]()
act(() => {
result.current[0]()
.ready()
.then((r) => {
expect(r[0]).toStrictEqual(okResponse);
});
})
.catch(() => undefined);

result.current[1].clear("clear-messgae");
});

await waitForNextUpdate();

void act(() => {
void result.current[0]()
act(() => {
result.current[0]()
.ready()
.catch((e) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Expand All @@ -117,12 +118,13 @@ describe("useRequest", () => {

unmount();

void act(() => {
void result.current[0]()
act(() => {
result.current[0]()
.ready()
.then((r) => {
expect(r[0]).toStrictEqual(okResponse);
});
})
.catch(() => undefined);

result.current[1].clear("unmount-messgae");
});
Expand Down
Loading

0 comments on commit e7e888a

Please sign in to comment.