Comments (4)
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;
from workers-types.
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
from workers-types.
I'm also wondering this. How are we supposed to use const cache = caches.default
right now it throws an error because default does not exist on CahceStorage. Is there a workaround?
from workers-types.
Thanks, now I just need to figure out how to set up the test environment.
from workers-types.
Related Issues (20)
- Missing properties on IncomingRequestCfPropertiesBotManagement HOT 1
- Incorrect D1 types HOT 2
- RequestInit is missing some properties like 'cache' HOT 3
- Generate types from `workerd` RTTI HOT 1
- RFC: Exportable types HOT 7
- Fix `request.cf` types
- Generate exportable version of `workers-types` HOT 1
- add JSDocs documentation in types
- Move overrides to `workerd` C++ source code HOT 1
- Include C++ parameter names in types generated from JSG RTTI HOT 2
- Get type hints on incoming Request object HOT 4
- IncomingRequestCfPropertiesGeographicInformation makes geo property access an error (regression from 3.17.0) HOT 7
- HtmlRewriter ElementHandler methods can only accept strings (not general Content) HOT 1
- (3.18.0) IncomingRequestCfPropertiesGeographicInformation is the wrong type HOT 2
- Class 'Request<ParamKeyType, Data>' incorrectly extends base class 'Body' HOT 1
- `new Request` bad type HOT 8
- addEventListener has a broken type definition HOT 1
- NPM Release @cloudflare/worker-types 4.20221111.0 HOT 2
- Add Symbol.iterator to WebScoketPair HOT 1
- What is Fetcher for? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workers-types.