Skip to content

Commit a01917b

Browse files
committed
Switch from toEmitMatchedValue in local-state/general tests
1 parent 0d0a250 commit a01917b

File tree

1 file changed

+59
-13
lines changed

1 file changed

+59
-13
lines changed

src/__tests__/local-state/general.ts

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,19 @@ describe("Cache manipulation", () => {
318318

319319
const stream = new ObservableStream(client.watchQuery({ query }));
320320

321-
await expect(stream).toEmitMatchedValue({ data: { field: 0 } });
321+
await expect(stream).toEmitTypedValue({
322+
data: { field: 0 },
323+
loading: false,
324+
networkStatus: NetworkStatus.ready,
325+
partial: false,
326+
});
322327
await client.mutate({ mutation });
323-
await expect(stream).toEmitMatchedValue({ data: { field: 1 } });
328+
await expect(stream).toEmitTypedValue({
329+
data: { field: 1 },
330+
loading: false,
331+
networkStatus: NetworkStatus.ready,
332+
partial: false,
333+
});
324334
});
325335

326336
it("should support writing to the cache with a local mutation using variables", () => {
@@ -617,20 +627,29 @@ describe("Sample apps", () => {
617627
client.addResolvers(resolvers);
618628
const stream = new ObservableStream(client.watchQuery({ query }));
619629

620-
await expect(stream).toEmitMatchedValue({
630+
await expect(stream).toEmitTypedValue({
621631
data: { count: 0, lastCount: 1 },
632+
loading: false,
633+
networkStatus: NetworkStatus.ready,
634+
partial: false,
622635
});
623636

624637
await client.mutate({ mutation: increment, variables: { amount: 2 } });
625638

626-
await expect(stream).toEmitMatchedValue({
639+
await expect(stream).toEmitTypedValue({
627640
data: { count: 2, lastCount: 1 },
641+
loading: false,
642+
networkStatus: NetworkStatus.ready,
643+
partial: false,
628644
});
629645

630646
await client.mutate({ mutation: decrement, variables: { amount: 1 } });
631647

632-
await expect(stream).toEmitMatchedValue({
648+
await expect(stream).toEmitTypedValue({
633649
data: { count: 1, lastCount: 1 },
650+
loading: false,
651+
networkStatus: NetworkStatus.ready,
652+
partial: false,
634653
});
635654
});
636655

@@ -856,7 +875,7 @@ describe("Combining client and server state/operations", () => {
856875
},
857876
},
858877
resolve: (_, { id }) => {
859-
return peopleData;
878+
return peopleData.find((p) => p.id === id);
860879
},
861880
},
862881
},
@@ -885,12 +904,27 @@ describe("Combining client and server state/operations", () => {
885904
const observable = client.watchQuery(request);
886905
const stream = new ObservableStream(observable);
887906

888-
await expect(stream).toEmitMatchedValue({ loading: false });
907+
await expect(stream).toEmitTypedValue({
908+
data: { people: { __typename: "Person", id: "1", name: "John Smith" } },
909+
loading: false,
910+
networkStatus: NetworkStatus.ready,
911+
partial: false,
912+
});
889913

890914
await observable.refetch({ id: 2 });
891915

892-
await expect(stream).toEmitMatchedValue({ loading: true });
893-
await expect(stream).toEmitMatchedValue({ loading: false });
916+
await expect(stream).toEmitTypedValue({
917+
data: undefined,
918+
loading: true,
919+
networkStatus: NetworkStatus.refetch,
920+
partial: true,
921+
});
922+
await expect(stream).toEmitTypedValue({
923+
data: { people: { __typename: "Person", id: "2", name: "Sara Smith" } },
924+
loading: false,
925+
networkStatus: NetworkStatus.ready,
926+
partial: false,
927+
});
894928
});
895929

896930
it("should correctly propagate an error from a client resolver", async () => {
@@ -975,8 +1009,11 @@ describe("Combining client and server state/operations", () => {
9751009

9761010
const stream = new ObservableStream(client.watchQuery({ query }));
9771011

978-
await expect(stream).toEmitMatchedValue({
1012+
await expect(stream).toEmitTypedValue({
9791013
data: { count: 0, lastCount: 1 },
1014+
loading: false,
1015+
networkStatus: NetworkStatus.ready,
1016+
partial: false,
9801017
});
9811018
});
9821019

@@ -1028,14 +1065,17 @@ describe("Combining client and server state/operations", () => {
10281065

10291066
const stream = new ObservableStream(client.watchQuery({ query }));
10301067

1031-
await expect(stream).toEmitMatchedValue({
1068+
await expect(stream).toEmitTypedValue({
10321069
data: {
10331070
user: {
10341071
firstName: "John",
10351072
lastName: "Doe",
10361073
__typename: "User",
10371074
},
10381075
},
1076+
loading: false,
1077+
networkStatus: NetworkStatus.ready,
1078+
partial: false,
10391079
});
10401080
});
10411081

@@ -1116,11 +1156,14 @@ describe("Combining client and server state/operations", () => {
11161156

11171157
const stream = new ObservableStream(client.watchQuery({ query }));
11181158

1119-
await expect(stream).toEmitMatchedValue({
1159+
await expect(stream).toEmitTypedValue({
11201160
data: {
11211161
count: 0,
11221162
user: { __typename: "User", firstName: "John" },
11231163
},
1164+
loading: false,
1165+
networkStatus: NetworkStatus.ready,
1166+
partial: false,
11241167
});
11251168

11261169
await client.mutate<any>({
@@ -1135,11 +1178,14 @@ describe("Combining client and server state/operations", () => {
11351178
},
11361179
});
11371180

1138-
await expect(stream).toEmitMatchedValue({
1181+
await expect(stream).toEmitTypedValue({
11391182
data: {
11401183
count: 1,
11411184
user: { __typename: "User", firstName: "Harry" },
11421185
},
1186+
loading: false,
1187+
networkStatus: NetworkStatus.ready,
1188+
partial: false,
11431189
});
11441190
});
11451191

0 commit comments

Comments
 (0)