Skip to content

Commit

Permalink
Use custom matchers where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Nov 27, 2024
1 parent cbfaca7 commit 5d319bd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 62 deletions.
32 changes: 12 additions & 20 deletions src/__tests__/fetchMore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,19 @@ describe("updateQuery on a simple query", () => {
const observable = client.watchQuery({ query });
const stream = new ObservableStream(observable);

{
const result = await stream.takeNext();

expect(result.data.entry.value).toBe(1);
}
await expect(stream).toEmitMatchedValue({
data: { entry: { value: 1 } },
});

observable.updateQuery((prevResult: any) => {
const res = cloneDeep(prevResult);
res.entry.value = 2;
return res;
});

{
const result = await stream.takeNext();

expect(result.data.entry.value).toBe(2);
}
await expect(stream).toEmitMatchedValue({
data: { entry: { value: 2 } },
});
});
});

Expand Down Expand Up @@ -124,23 +120,19 @@ describe("updateQuery on a query with required and optional variables", () => {

const stream = new ObservableStream(observable);

{
const result = await stream.takeNext();

expect(result.data.entry.value).toBe(1);
}
await expect(stream).toEmitMatchedValue({
data: { entry: { value: 1 } },
});

observable.updateQuery((prevResult: any) => {
const res = cloneDeep(prevResult);
res.entry.value = 2;
return res;
});

{
const result = await stream.takeNext();

expect(result.data.entry.value).toBe(2);
}
await expect(stream).toEmitMatchedValue({
data: { entry: { value: 2 } },
});
});
});

Expand Down
46 changes: 19 additions & 27 deletions src/cache/inmemory/__tests__/fragmentRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,27 @@ describe("FragmentRegistry", () => {
client.watchQuery({ query, fetchPolicy: "cache-and-network" })
);

{
const result = await stream.takeNext();

expect(result).toEqual({
loading: true,
networkStatus: NetworkStatus.loading,
data: {
__typename: "Query",
source: "local",
},
});
}

{
const result = await stream.takeNext();

expect(result).toEqual({
loading: false,
networkStatus: NetworkStatus.ready,
data: {
__typename: "Query",
source: "link",
},
});
await expect(stream).toEmitValue({
loading: true,
networkStatus: NetworkStatus.loading,
data: {
__typename: "Query",
source: "local",
},
});

expect(cache.readQuery({ query })).toEqual({
await expect(stream).toEmitValue({
loading: false,
networkStatus: NetworkStatus.ready,
data: {
__typename: "Query",
source: "link",
});
}
},
});

expect(cache.readQuery({ query })).toEqual({
source: "link",
});
});

it("throws an error when not all used fragments are defined", () => {
Expand Down
26 changes: 11 additions & 15 deletions src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4090,22 +4090,18 @@ describe("type policies", function () {

const stream = new ObservableStream(observable);

{
const result = await stream.takeNext();

expect(result).toEqual({
loading: false,
networkStatus: NetworkStatus.ready,
data: {
search: {
edges: firstEdges,
pageInfo: firstPageInfo,
totalCount: 1292,
},
await expect(stream).toEmitValue({
loading: false,
networkStatus: NetworkStatus.ready,
data: {
search: {
edges: firstEdges,
pageInfo: firstPageInfo,
totalCount: 1292,
},
});
expect(cache.extract()).toMatchSnapshot();
}
},
});
expect(cache.extract()).toMatchSnapshot();

observable.fetchMore({ variables: secondVariables });

Expand Down

0 comments on commit 5d319bd

Please sign in to comment.