Skip to content

Commit

Permalink
Test that we preserve no-cache with notifyOnNetworkStatusChange set
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenn Creighton committed Mar 9, 2021
1 parent b0e532b commit 7d3f4f0
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/core/__tests__/fetchPolicies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,63 @@ describe('no-cache', () => {
})
.then(resolve, reject);
});

describe('when notifyOnNetworkStatusChange is set', () => {
itAsync('does not save the data to the cache on success', (resolve, reject) => {
let called = 0;
const inspector = new ApolloLink((operation, forward) => {
called++;
return forward(operation).map(result => {
called++;
return result;
});
});

const client = new ApolloClient({
link: inspector.concat(createLink(reject)),
cache: new InMemoryCache({ addTypename: false }),
});

return client.query({ query, fetchPolicy: 'no-cache', notifyOnNetworkStatusChange: true }).then(
() => client.query({ query }).then(actualResult => {
expect(stripSymbols(actualResult.data)).toEqual(result);
// the second query couldn't read anything from the cache
expect(called).toBe(4);
}),
).then(resolve, reject);
});

itAsync('does not save data to the cache on failure', (resolve, reject) => {
let called = 0;
const inspector = new ApolloLink((operation, forward) => {
called++;
return forward(operation).map(result => {
called++;
return result;
});
});

const client = new ApolloClient({
link: inspector.concat(createFailureLink()),
cache: new InMemoryCache({ addTypename: false }),
});

let didFail = false;
return client
.query({ query, fetchPolicy: 'no-cache', notifyOnNetworkStatusChange: true })
.catch(e => {
expect(e.message).toMatch('query failed');
didFail = true;
})
.then(() => client.query({ query }).then(actualResult => {
expect(stripSymbols(actualResult.data)).toEqual(result);
// the first error doesn't call .map on the inspector
expect(called).toBe(3);
expect(didFail).toBe(true);
}))
.then(resolve, reject);
});
});
});

describe('cache-first', () => {
Expand Down

0 comments on commit 7d3f4f0

Please sign in to comment.