This repository was archived by the owner on Feb 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
cache types #8
Milestone
Comments
I'm also wondering this. How are we supposed to use |
Workaround for now is: export interface Caches {
default: {
put(request: Request | string, response: Response): Promise<undefined>;
match(request: Request | string): Promise<Response | undefined>;
};
}
declare let caches: Caches; |
Thanks, now I just need to figure out how to set up the test environment. |
just implement interface, e.g. export interface Caches {
default: {
put(request: Request | string, response: Response): Promise<undefined>;
match(request: Request | string): Promise<Response | undefined>;
};
}
declare let caches: Caches;
export interface GlobalCaches {
caches: Caches;
}
export function makeFakeCache(): GlobalCaches {
return {
caches: {
default: {
put: (): Promise<undefined> => Promise.resolve(undefined),
match: (): Promise<Response | undefined> => Promise.resolve(undefined),
},
},
};
}
beforeEach(() => {
Object.assign(global, makeServiceWorkerEnv(), makeFakeCache())
});
test('handler should use cache', async () => {
caches.default.match = (): Promise<Response | undefined> =>
Promise.resolve(new Response(JSON.stringify({ foo: "bar" })));
const result = await doWork() // doWork inside uses global caches and trying to match on it will return { foo: "bar" }
// ...
}); or use some mocking libraries, e.g. sinon, or maybe something built into jest, etc |
Closed
2 tasks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
wondering whether cache types will be added here in future?
The text was updated successfully, but these errors were encountered: