Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mtbrault/nextjs-http-supertest
npm package to get an http server parsing your nextJS app to link endpoint with handler
https://github.com/mtbrault/nextjs-http-supertest
Last synced: about 1 month ago
JSON representation
npm package to get an http server parsing your nextJS app to link endpoint with handler
- Host: GitHub
- URL: https://github.com/mtbrault/nextjs-http-supertest
- Owner: mtbrault
- Created: 2023-01-16T13:52:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-15T08:44:09.000Z (about 2 months ago)
- Last Synced: 2024-10-15T08:51:15.160Z (about 2 months ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 14
- Watchers: 1
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome - mtbrault/nextjs-http-supertest - npm package to get an http server parsing your nextJS app to link endpoint with handler (JavaScript)
README
# nextjs-http-supertest
This package do several things:
* Parse the file under your `pages/api` nextJS folder
* Link your handler with the HTTP endpoint
* When performing a request with `supertest`, parsing the URL and the query parameters to call the correct handler.Requirement: Your api handlers must be located under `pages/api` or `src/pages/api` at the root of your nextJS repository.
It returns an http server instance (do not forget to close it after running your test suite).
Example below in a `toto.test.js` jest file.
```javascript
import request from 'supertest';
import server from 'nextjs-http-supertest';describe('my super test suite', () => {
afterAll(() => {
server.close(); // don't forget to close your server after your tests
})it('200: Should return a toto array', async () => {
const r = await request(server).get('/api/toto').query({ offset: 0, limit: 10 });
expect(r.statusCode).toEqual(200);
expect(r.body.length).toEqual(10);
})
})
```It handles typescript