Skip to content

Commit

Permalink
added test dispose subscription and change return in loadquery subscr…
Browse files Browse the repository at this point in the history
…ibe function
  • Loading branch information
morrys committed Sep 24, 2020
1 parent 4be49a4 commit ea45b53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions __tests__/usePreloadQuery-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -798,5 +798,16 @@ describe('usePreloadQuery', () => {
},
});
});

it('dispose subscription', () => {
const callback = jest.fn(() => {});
const dispose = prefetched.subscribe(callback);
dispose();
prefetched.next(environment, params, { id: '4' });
dataSource.next(response);
dataSource.complete();
TestRenderer.act(() => jest.runAllImmediates());
expect(callback).not.toBeCalled();
});
});
});
4 changes: 3 additions & 1 deletion src/loadQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ const internalLoadQuery = <TOperationType extends OperationType = OperationType>

const subscribe = (callback: (value) => any): (() => void) => {
listener = callback;
return dispose;
return (): void => {
listener = null;
};
};
return {
next,
Expand Down

0 comments on commit ea45b53

Please sign in to comment.