diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-04-20 12:46:21 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-04-21 08:12:39 +0200 |
| commit | df99bc1790ac00a73a41e3449db79a12ee8fd72d (patch) | |
| tree | c621d5fd7c804b5a0a17ee385728cd5e459a4118 | |
| parent | 0ed2aa6e8a5be20bbc5b252968163eeace7d872d (diff) | |
| download | mullvadvpn-df99bc1790ac00a73a41e3449db79a12ee8fd72d.tar.xz mullvadvpn-df99bc1790ac00a73a41e3449db79a12ee8fd72d.zip | |
Add test for multiple quick fetch calls
| -rw-r--r-- | gui/test/account-data-cache.spec.ts | 18 |
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; + }); + }); }); |
