Skip to content

Commit

Permalink
Update tests with new case
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jul 6, 2021
1 parent e15c7c5 commit 1bfd974
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion packages/core/src/exchanges/ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,40 @@ it('deletes cached results in non-suspense environments', async () => {

await Promise.resolve();

expect(Object.keys(ssr.extractData()).length).toBe(0);
expect(ssr.extractData()[queryOperation.key]).toBe(null);
expect(onPush).toHaveBeenCalledWith(queryResponse);

// NOTE: The operation should not be duplicated
expect(output).not.toHaveBeenCalled();
});

it('never allows restoration of invalidated results', async () => {
client.suspense = false;

const onPush = jest.fn();
const initialState = { [queryOperation.key]: serializedQueryResponse as any };

const ssr = ssrExchange({
isClient: true,
initialState: { ...initialState },
});

const { source: ops$, next } = input;
const exchange = ssr(exchangeInput)(ops$);

pipe(exchange, forEach(onPush));
next(queryOperation);

await Promise.resolve();

expect(ssr.extractData()[queryOperation.key]).toBe(null);
expect(onPush).toHaveBeenCalledTimes(1);
expect(output).not.toHaveBeenCalled();

ssr.restoreData(initialState);
expect(ssr.extractData()[queryOperation.key]).toBe(null);

next(queryOperation);
expect(onPush).toHaveBeenCalledTimes(2);
expect(output).toHaveBeenCalledTimes(1);
});

0 comments on commit 1bfd974

Please sign in to comment.