summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-04-20 12:46:21 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-04-21 08:12:39 +0200
commitdf99bc1790ac00a73a41e3449db79a12ee8fd72d (patch)
treec621d5fd7c804b5a0a17ee385728cd5e459a4118
parent0ed2aa6e8a5be20bbc5b252968163eeace7d872d (diff)
downloadmullvadvpn-df99bc1790ac00a73a41e3449db79a12ee8fd72d.tar.xz
mullvadvpn-df99bc1790ac00a73a41e3449db79a12ee8fd72d.zip
Add test for multiple quick fetch calls
-rw-r--r--gui/test/account-data-cache.spec.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/gui/test/account-data-cache.spec.ts b/gui/test/account-data-cache.spec.ts
index 50118ab20d..7a485b878a 100644
--- a/gui/test/account-data-cache.spec.ts
+++ b/gui/test/account-data-cache.spec.ts
@@ -258,4 +258,22 @@ describe('IAccountData cache', () => {
expect(updateHandler).to.have.been.called.twice;
});
});
+ it('should not perform a fetch if called twice synchronously', async () => {
+ const fetchSpy = spy();
+ const update = new Promise((resolve, _reject) => {
+ const fetch = () => {
+ fetchSpy();
+ return Promise.resolve(dummyAccountData);
+ };
+
+ const cache = new AccountDataCache(fetch, () => {});
+ const onError = (_error: Error) => AccountFetchRetryAction.stop;
+ cache.fetch(dummyAccountToken, { onFinish: () => {}, onError });
+ cache.fetch(dummyAccountToken, { onFinish: () => resolve(), onError });
+ });
+
+ return expect(update).to.eventually.be.fulfilled.then(() => {
+ expect(fetchSpy).to.have.been.called.once;
+ });
+ });
});