clo4 / deno_mock_fetch Goto Github PK
View Code? Open in Web Editor NEWUse URLPattern syntax to mock fetch responses
Home Page: https://doc.deno.land/https/deno.land/x/mock_fetch/mod.ts
License: MIT License
Use URLPattern syntax to mock fetch responses
Home Page: https://doc.deno.land/https/deno.land/x/mock_fetch/mod.ts
License: MIT License
Hey, it would be very convient to have a utility function to mock the route and remove the route straight after it gets 1 call. Maybe even a mock_n one.
I'm trying to use this to test my retry fetch util, but it doesn't seem to be working. I can see the timeout is being called, but it doesn't seem to timeout the request. Do you know if this is possible to test?
Code
const {timeout = 10000} = options;
const controller = new AbortController();
const id = setTimeout(() => {
controller.abort();
}, timeout);
res = await fetch(url, {
...options,
signal: controller.signal
});
clearTimeout(id);
Test
let called = 0;
mf.mock("GET@/api/hello/:name", async (_req: Request, params: any) => {
if (called++ === 0) {
await sleep(2);
return new Response();
}
return new Response(`Hello, ${params["name"]} ${called}!`, {
status: 200,
});
});
const res = await retryFetch("https://localhost:1234/api/hello/SeparateRecords", {timeout: 1000});
assertEquals(2, called);
assertEquals('Hello, SeparateRecords 2!', await res.text());
Some requirements for the new API
It might be easier to vendor the dependency on router
for this so there's no duplication! Can also use a different syntax, instead of GET@/...
it can use GET /...
Hiya! Randomly stumbled upon this when I needed a mock-fetch module for work and this looks awesome! Thanks for the credit btw, was kinda shook when I read the README and all of the sudden my name and project pops up in the credits ๐. But yeah, like the title says it would be nice if you would update router to version 0.0.12.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.