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

Refactor useQuery tests to use toEqualQueryResult - Part 2 #12274

Merged
merged 33 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
127fff2
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
c7afbd3
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
dceb9e4
Add TODO comment with suggestion for refactoring
jerelmiller Jan 14, 2025
839fa44
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
94e0087
Add TODO comment with suggestion for refactoring
jerelmiller Jan 14, 2025
ed82bcc
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
5ea574d
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
63cc1f5
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
fa089f4
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
60dd6a0
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
a32c8be
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
b3685d3
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
d3d9493
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
689ba12
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
bca257c
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
eba7f2d
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
173020b
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
59a4d3d
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
ac36a54
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
9231eae
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
bcb4fd3
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
8962f95
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
5fc0b20
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
0f816b8
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
0a7e80c
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
73ce74f
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
8268028
Add todo comment to refactor test
jerelmiller Jan 14, 2025
f4a9469
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
4090cef
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
c8b57fb
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
6fe235e
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
f2747ae
Rewrite test with toEqualQueryResult
jerelmiller Jan 14, 2025
ece38b5
Rewrite test with renderHookToSnapshotStream and toEqualQueryResult
jerelmiller Jan 14, 2025
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
Prev Previous commit
Next Next commit
Rewrite test with toEqualQueryResult
  • Loading branch information
jerelmiller committed Jan 16, 2025
commit d3d94931418432ee88dad9deb83f5081e52f787c
95 changes: 61 additions & 34 deletions src/react/hooks/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3334,55 +3334,82 @@ describe("useQuery Hook", () => {
{ wrapper }
);

expect(result.current.loading).toBe(true);
expect(result.current.data).toBe(undefined);
expect(result.current).toEqualQueryResult({
data: undefined,
called: true,
loading: true,
networkStatus: NetworkStatus.loading,
previousData: undefined,
variables: {},
});

await waitFor(
() => {
expect(result.current.data).toEqual({ hello: "world 1" });
expect(result.current).toEqualQueryResult({
data: { hello: "world 1" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: undefined,
variables: {},
});
},
{ interval: 1 }
);

expect(result.current.loading).toBe(false);

await waitFor(
() => {
expect(result.current.data).toEqual({ hello: "world 2" });
},
{ interval: 1 }
);
await jest.advanceTimersByTimeAsync(12);
expect(result.current).toEqualQueryResult({
data: { hello: "world 2" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: { hello: "world 1" },
variables: {},
});

skipPollAttempt.mockImplementation(() => true);
expect(result.current.loading).toBe(false);

await jest.advanceTimersByTime(12);
await waitFor(
() => expect(result.current.data).toEqual({ hello: "world 2" }),
{ interval: 1 }
);
await jest.advanceTimersByTimeAsync(12);
expect(result.current).toEqualQueryResult({
data: { hello: "world 2" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: { hello: "world 1" },
variables: {},
});

await jest.advanceTimersByTime(12);
await waitFor(
() => expect(result.current.data).toEqual({ hello: "world 2" }),
{ interval: 1 }
);
await jest.advanceTimersByTimeAsync(12);
expect(result.current).toEqualQueryResult({
data: { hello: "world 2" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: { hello: "world 1" },
variables: {},
});

await jest.advanceTimersByTime(12);
await waitFor(
() => expect(result.current.data).toEqual({ hello: "world 2" }),
{ interval: 1 }
);
await jest.advanceTimersByTimeAsync(12);
expect(result.current).toEqualQueryResult({
data: { hello: "world 2" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: { hello: "world 1" },
variables: {},
});

skipPollAttempt.mockImplementation(() => false);
expect(result.current.loading).toBe(false);

await waitFor(
() => {
expect(result.current.data).toEqual({ hello: "world 3" });
},
{ interval: 1 }
);
await jest.advanceTimersByTimeAsync(12);
expect(result.current).toEqualQueryResult({
data: { hello: "world 3" },
called: true,
loading: false,
networkStatus: NetworkStatus.ready,
previousData: { hello: "world 2" },
variables: {},
});
});
});
});
Expand Down