Comments (2)
Hi @metrue
As far as I know, there are two ways:
- Use
edge-mock
- https://github.com/samuelcolvin/edge-mock - Use
miniflare Jest Environment
- https://miniflare.dev/testing/jest
edge-mock
is used in benchmark/handleEvent. miniflare Jest Environment
is used in example/blog
I tried both to test with FormData
. minflare
is better than edge-mock
. miniflare
reproduces Cloudflare Workers API faithfully. This tests will be passed:
describe('FormData', () => {
it('formData - application/x-www-form-urlencoded', async () => {
app.post('/', async (c) => {
const form = await c.req.formData()
// console.log(c.req.headers.get('Content-Type'))
// => application/x-www-form-urlencoded;charset=UTF-
return c.text((form.get('aaa') || '').toString())
})
const searchParams = new URLSearchParams()
searchParams.append('aaa', 'bbb')
const req = new Request('https://localhost/', {
method: 'POST',
body: searchParams,
})
const res = await app.dispatch(req)
expect(res.status).toBe(200)
expect(await res.text()).toBe('bbb')
})
it('formData - multipart/form-data', async () => {
app.post('/', async (c) => {
const form = await c.req.formData()
// console.log(c.req.headers.get('Content-Type'))
// multipart/form-data; boundary=----formdata-undici-0.12093121571495491
return c.text((form.get('aaa') || '').toString())
})
const formData = new FormData()
formData.append('aaa', 'bbb')
const req = new Request('https://localhost/', {
method: 'POST',
body: formData,
})
const res = await app.dispatch(req)
expect(res.status).toBe(200)
expect(await res.text()).toBe('bbb')
})
})
})
And, miniflare Jest Environment
provides Environment. No need to call a method like makeServiceWorkerEnv()
.
Unfortunately, miniflare dump warning messages, but it will be resolved in the near future.
(node:73360) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(node:73360) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
I think miniflare Jest Environment
is best. How about you?
from hono.
Yes, miniflare Jest Environment
is better, let's go with it.
from hono.
Related Issues (20)
- In Hono RPC, specifying an array as a FormData value will result in type error HOT 2
- `File` to `Blob` HOT 7
- 4.4.12 breaks client typing when using use with a path HOT 7
- Support SPA like express HOT 9
- Export type "StatusCode" HOT 3
- Mark `app.fire` as deprecated
- do not suggest unnecenssary route path HOT 2
- 4.4.7 broke array types in Context HOT 7
- bug: JSONParsed type not correctly working for generic type HOT 14
- Uploading a file using FormData from React Native to Hono HOT 3
- 'client' is of type 'unknown' when using route HOT 8
- Chaining routes in modular application seems impossible HOT 11
- hono/client hc<>() breaks when using with BunJS build HOT 4
- c.json() not setting status code correctly HOT 7
- i want the feature to list all routes like `rails routes`. HOT 1
- env method doesn't work on Cloudflare Pages HOT 8
- Issue tracking for experimental features HOT 2
- React + Vite SSR with Hono HOT 2
- Output of testClient returns a status function HOT 5
- Hono doesn't consider status codes from middlewares with `testClient` HOT 6
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 hono.