Skip to content

Commit fa4348a

Browse files
authored
Remove toEmitMatchedValue in favor or toEmitTypedValue (#12517)
1 parent 4418600 commit fa4348a

File tree

11 files changed

+253
-139
lines changed

11 files changed

+253
-139
lines changed

src/__tests__/ApolloClient.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,12 @@ describe("ApolloClient", () => {
12151215
const observable = client.watchQuery<Data>({ query });
12161216
const stream = new ObservableStream(observable);
12171217

1218-
await expect(stream).toEmitMatchedValue({ data });
1218+
await expect(stream).toEmitTypedValue({
1219+
data,
1220+
loading: false,
1221+
networkStatus: NetworkStatus.ready,
1222+
partial: false,
1223+
});
12191224
expect(observable.getCurrentResult().data).toEqual(data);
12201225

12211226
const readData = client.readQuery<Data>({ query });
@@ -1245,7 +1250,12 @@ describe("ApolloClient", () => {
12451250
},
12461251
};
12471252

1248-
await expect(stream).toEmitMatchedValue({ data: expectation });
1253+
await expect(stream).toEmitTypedValue({
1254+
data: expectation,
1255+
loading: false,
1256+
networkStatus: NetworkStatus.ready,
1257+
partial: false,
1258+
});
12491259
expect(client.readQuery<Data>({ query })).toEqual(expectation);
12501260
});
12511261

@@ -1254,7 +1264,12 @@ describe("ApolloClient", () => {
12541264
const observable = client.watchQuery<Data>({ query });
12551265
const stream = new ObservableStream(observable);
12561266

1257-
await expect(stream).toEmitMatchedValue({ data });
1267+
await expect(stream).toEmitTypedValue({
1268+
data,
1269+
loading: false,
1270+
networkStatus: NetworkStatus.ready,
1271+
partial: false,
1272+
});
12581273

12591274
expect(observable.getCurrentResult().data).toEqual(data);
12601275

src/__tests__/client.ts

Lines changed: 98 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,12 @@ describe("client", () => {
926926
const handle = client.watchQuery({ query });
927927
const stream = new ObservableStream(handle);
928928

929-
await expect(stream).toEmitMatchedValue({ data });
929+
await expect(stream).toEmitTypedValue({
930+
data,
931+
loading: false,
932+
networkStatus: NetworkStatus.ready,
933+
partial: false,
934+
});
930935
});
931936

932937
it("should be able to transform queries", async () => {
@@ -1864,8 +1869,18 @@ describe("client", () => {
18641869

18651870
const stream = new ObservableStream(obs);
18661871

1867-
await expect(stream).toEmitMatchedValue({ data: initialData });
1868-
await expect(stream).toEmitMatchedValue({ data: networkFetch });
1872+
await expect(stream).toEmitTypedValue({
1873+
data: initialData,
1874+
loading: true,
1875+
networkStatus: NetworkStatus.loading,
1876+
partial: false,
1877+
});
1878+
await expect(stream).toEmitTypedValue({
1879+
data: networkFetch,
1880+
loading: false,
1881+
networkStatus: NetworkStatus.ready,
1882+
partial: false,
1883+
});
18691884

18701885
await expect(stream).not.toEmitAnything();
18711886
});
@@ -1886,9 +1901,11 @@ describe("client", () => {
18861901
});
18871902
const stream = new ObservableStream(obs);
18881903

1889-
await expect(stream).toEmitMatchedValue({
1890-
loading: false,
1904+
await expect(stream).toEmitTypedValue({
18911905
data: networkFetch,
1906+
loading: false,
1907+
networkStatus: NetworkStatus.ready,
1908+
partial: false,
18921909
});
18931910

18941911
await expect(stream).not.toEmitAnything();
@@ -1982,7 +1999,12 @@ describe("client", () => {
19821999
const obs = client.watchQuery({ query, fetchPolicy: "cache-first" });
19832000
const stream = new ObservableStream(obs);
19842001

1985-
await expect(stream).toEmitMatchedValue({ data });
2002+
await expect(stream).toEmitTypedValue({
2003+
data,
2004+
loading: false,
2005+
networkStatus: NetworkStatus.ready,
2006+
partial: false,
2007+
});
19862008

19872009
await expect(
19882010
obs.reobserve({ query, fetchPolicy: "standby" })
@@ -2011,7 +2033,12 @@ describe("client", () => {
20112033
const obs = client.watchQuery({ query, fetchPolicy: "cache-first" });
20122034
const stream = new ObservableStream(obs);
20132035

2014-
await expect(stream).toEmitMatchedValue({ data });
2036+
await expect(stream).toEmitTypedValue({
2037+
data,
2038+
loading: false,
2039+
networkStatus: NetworkStatus.ready,
2040+
partial: false,
2041+
});
20152042

20162043
await expect(
20172044
obs.reobserve({ query, fetchPolicy: "standby" })
@@ -2022,7 +2049,12 @@ describe("client", () => {
20222049
void obs.reobserve({ query, fetchPolicy: "cache-first" });
20232050
}, 10);
20242051

2025-
await expect(stream).toEmitMatchedValue({ data: data2 });
2052+
await expect(stream).toEmitTypedValue({
2053+
data: data2,
2054+
loading: false,
2055+
networkStatus: NetworkStatus.ready,
2056+
partial: false,
2057+
});
20262058
await expect(stream).not.toEmitAnything();
20272059
});
20282060

@@ -2506,7 +2538,12 @@ describe("client", () => {
25062538
await client.resetStore();
25072539
expect(count).toBe(2);
25082540

2509-
await expect(stream).toEmitMatchedValue({ data });
2541+
await expect(stream).toEmitTypedValue({
2542+
data,
2543+
loading: false,
2544+
networkStatus: NetworkStatus.ready,
2545+
partial: false,
2546+
});
25102547
await expect(stream).toEmitNext();
25112548

25122549
expect(onResetStoreOne).toHaveBeenCalled();
@@ -3561,8 +3598,18 @@ describe("@connection", () => {
35613598

35623599
const stream = new ObservableStream(obs);
35633600

3564-
await expect(stream).toEmitMatchedValue({ data: initialData });
3565-
await expect(stream).toEmitMatchedValue({ data: networkFetch });
3601+
await expect(stream).toEmitTypedValue({
3602+
data: initialData,
3603+
loading: true,
3604+
networkStatus: NetworkStatus.loading,
3605+
partial: false,
3606+
});
3607+
await expect(stream).toEmitTypedValue({
3608+
data: networkFetch,
3609+
loading: false,
3610+
networkStatus: NetworkStatus.ready,
3611+
partial: false,
3612+
});
35663613
await expect(stream).not.toEmitAnything();
35673614
});
35683615

@@ -3625,15 +3672,25 @@ describe("@connection", () => {
36253672
const obs = client.watchQuery({ query });
36263673
const stream = new ObservableStream(obs);
36273674

3628-
await expect(stream).toEmitMatchedValue({ data: { count: "initial" } });
3675+
await expect(stream).toEmitTypedValue({
3676+
data: { count: "initial" },
3677+
loading: false,
3678+
networkStatus: NetworkStatus.ready,
3679+
partial: false,
3680+
});
36293681
expect(nextFetchPolicyCallCount).toBe(1);
36303682

36313683
// Refetching makes a copy of the current options, which
36323684
// includes options.nextFetchPolicy, so the inner
36333685
// nextFetchPolicy function ends up getting called twice.
36343686
void obs.refetch();
36353687

3636-
await expect(stream).toEmitMatchedValue({ data: { count: 0 } });
3688+
await expect(stream).toEmitTypedValue({
3689+
data: { count: 0 },
3690+
loading: false,
3691+
networkStatus: NetworkStatus.ready,
3692+
partial: false,
3693+
});
36373694
expect(nextFetchPolicyCallCount).toBe(2);
36383695

36393696
client.writeQuery({
@@ -3643,12 +3700,22 @@ describe("@connection", () => {
36433700
},
36443701
});
36453702

3646-
await expect(stream).toEmitMatchedValue({ data: { count: "secondary" } });
3703+
await expect(stream).toEmitTypedValue({
3704+
data: { count: "secondary" },
3705+
loading: false,
3706+
networkStatus: NetworkStatus.ready,
3707+
partial: false,
3708+
});
36473709
expect(nextFetchPolicyCallCount).toBe(3);
36483710

36493711
client.cache.evict({ fieldName: "count" });
36503712

3651-
await expect(stream).toEmitMatchedValue({ data: { count: 1 } });
3713+
await expect(stream).toEmitTypedValue({
3714+
data: { count: 1 },
3715+
loading: false,
3716+
networkStatus: NetworkStatus.ready,
3717+
partial: false,
3718+
});
36523719
expect(nextFetchPolicyCallCount).toBe(4);
36533720
expect(obs.options.fetchPolicy).toBe("cache-first");
36543721

@@ -3698,9 +3765,11 @@ describe("@connection", () => {
36983765

36993766
const stream = new ObservableStream(observable);
37003767

3701-
await expect(stream).toEmitMatchedValue({
3702-
loading: false,
3768+
await expect(stream).toEmitTypedValue({
37033769
data: { linkCount: 1 },
3770+
loading: false,
3771+
networkStatus: NetworkStatus.ready,
3772+
partial: false,
37043773
});
37053774
expect(fetchPolicyRecord).toEqual(["cache-first"]);
37063775

@@ -3715,9 +3784,11 @@ describe("@connection", () => {
37153784

37163785
expect(fetchPolicyRecord).toEqual(["cache-first", "network-only"]);
37173786

3718-
await expect(stream).toEmitMatchedValue({
3719-
loading: false,
3787+
await expect(stream).toEmitTypedValue({
37203788
data: { linkCount: 2 },
3789+
loading: false,
3790+
networkStatus: NetworkStatus.ready,
3791+
partial: false,
37213792
});
37223793
expect(fetchPolicyRecord).toEqual(["cache-first", "network-only"]);
37233794

@@ -3738,14 +3809,18 @@ describe("@connection", () => {
37383809
"cache-and-network",
37393810
]);
37403811

3741-
await expect(stream).toEmitMatchedValue({
3742-
loading: true,
3812+
await expect(stream).toEmitTypedValue({
37433813
data: { linkCount: 2 },
3814+
loading: true,
3815+
networkStatus: NetworkStatus.loading,
3816+
partial: false,
37443817
});
37453818

3746-
await expect(stream).toEmitMatchedValue({
3747-
loading: false,
3819+
await expect(stream).toEmitTypedValue({
37483820
data: { linkCount: 3 },
3821+
loading: false,
3822+
networkStatus: NetworkStatus.ready,
3823+
partial: false,
37493824
});
37503825

37513826
expect(fetchPolicyRecord).toEqual([

src/__tests__/fetchMore.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ describe("updateQuery on a simple query", () => {
5555
const observable = client.watchQuery({ query });
5656
const stream = new ObservableStream(observable);
5757

58-
await expect(stream).toEmitMatchedValue({
59-
data: { entry: { value: 1 } },
58+
await expect(stream).toEmitTypedValue({
59+
data: { __typename: "Query", entry: { __typename: "Entry", value: 1 } },
60+
loading: false,
61+
networkStatus: NetworkStatus.ready,
62+
partial: false,
6063
});
6164

6265
observable.updateQuery((prevResult: any) => {
@@ -65,8 +68,11 @@ describe("updateQuery on a simple query", () => {
6568
return res;
6669
});
6770

68-
await expect(stream).toEmitMatchedValue({
69-
data: { entry: { value: 2 } },
71+
await expect(stream).toEmitTypedValue({
72+
data: { __typename: "Query", entry: { __typename: "Entry", value: 2 } },
73+
loading: false,
74+
networkStatus: NetworkStatus.ready,
75+
partial: false,
7076
});
7177
});
7278
});
@@ -117,8 +123,11 @@ describe("updateQuery on a query with required and optional variables", () => {
117123

118124
const stream = new ObservableStream(observable);
119125

120-
await expect(stream).toEmitMatchedValue({
121-
data: { entry: { value: 1 } },
126+
await expect(stream).toEmitTypedValue({
127+
data: { __typename: "Query", entry: { __typename: "Entry", value: 1 } },
128+
loading: false,
129+
networkStatus: NetworkStatus.ready,
130+
partial: false,
122131
});
123132

124133
observable.updateQuery((prevResult: any) => {
@@ -127,8 +136,11 @@ describe("updateQuery on a query with required and optional variables", () => {
127136
return res;
128137
});
129138

130-
await expect(stream).toEmitMatchedValue({
131-
data: { entry: { value: 2 } },
139+
await expect(stream).toEmitTypedValue({
140+
data: { __typename: "Query", entry: { __typename: "Entry", value: 2 } },
141+
loading: false,
142+
networkStatus: NetworkStatus.ready,
143+
partial: false,
132144
});
133145
});
134146
});

0 commit comments

Comments
 (0)