superset/superset-frontend/temporary_superset_ui/superset-ui/test/setupTests.ts
Beto Dealmeida a63f947ff5 feat: add support for conditional get requests (#119)
* feat: add support for conditional requests

* feat: add unit tests for conditional requests

* feat: use invariant

* feat: add type guard

* feat: fix lint

* feat: add more unit tests
2021-11-26 11:44:46 +08:00

31 lines
728 B
TypeScript

const caches = {};
class Cache {
cache: object;
constructor(key: string) {
caches[key] = caches[key] || {};
this.cache = caches[key];
}
match(url: string): Promise<Response | undefined> {
return new Promise((resolve, reject) => resolve(this.cache[url]));
}
delete(url: string): Promise<boolean> {
delete this.cache[url];
return new Promise((resolve, reject) => resolve(true));
}
put(url: string, response: Response): Promise<void> {
this.cache[url] = response;
return Promise.resolve();
}
};
class CacheStorage {
open(key: string): Promise<Cache> {
return new Promise((resolve, reject) => {
resolve(new Cache(key));
});
}
};
global.caches = new CacheStorage();