menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Team

Are there any good mocking libraries for Micro's Request/Response objects?

October 4, 2019 at 12:30pm

Are there any good mocking libraries for Micro's Request/Response objects?

October 4, 2019 at 12:30pm

There is the popular node-mocks-http package, but this is primarily written for express users, so the req/res objects aren't exactly right. (And if your project is TypeScript, you actually have to add

/express as a dependency to make it work, which feels a bit ugly in if you're using Micro...)


October 6, 2019 at 5:59pm

Zeit Micro is basically building on top of the standard http.IncomingRequest and http.ServerResponse objects, so you can use the node-mocks-http or this package to mock out the request and response: mock-http

If you use Zeit now http extentions, then you can just use the types from the now/node package:

import { NowRequest, NowResponse } from '@now/node';
const mockedReq: NowRequest = new mock.Request({ ... });
const mockedRes: NowResponse = new mock.Response({ .. });
like-fill
1
  • reply
  • like
private
This channel has been archived