Installations
npm install jest-express
Score
99.1
Supply Chain
100
Quality
76
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Developer
jameswlane
Module System
CommonJS
Statistics
181 Stars
1,006 Commits
27 Forks
9 Watching
14 Branches
15 Contributors
Updated on 30 Oct 2024
Languages
TypeScript (98.89%)
JavaScript (1.11%)
Total Downloads
Cumulative downloads
Total Downloads
10,517,752
Last day
48.5%
1,654
Compared to previous day
Last week
4.7%
42,673
Compared to previous week
Last month
-3%
178,541
Compared to previous month
Last year
-17.8%
2,086,065
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
24
Jest Express
Mock Express for testing with Jest
- express()
- Application
- Request
- baseUrl
- body
- cookies
- fresh
- hostname
- ip
- ips
- method
- originalUrl
- params
- path
- protocol
- query
- route
- baseUrl
- secure
- signedCookies
- stale
- subdomains
- xhr
- accepts()
- acceptsCharsets()
- acceptsEncodings()
- acceptsLanguages()
- get()
- is()
- range()
- setBaseUrl()
- setBody()
- setCookies()
- setFresh()
- setHostname()
- setHeaders()
- setIp()
- setIps()
- setMethod()
- setOriginalUrl()
- setParams()
- setPath()
- setProtocol()
- setQuery()
- setRoute()
- setSecure()
- setSignedCookies()
- setStale()
- setSubdomains()
- setXhr()
- resetMocked()
- Response
- headersSent
- locals
- append()
- attachment()
- body
- cookie()
- clearCookie()
- download()
- end()
- format()
- get()
- getHeader()
- header()
- json()
- jsonp()
- links()
- location()
- redirect()
- render()
- send()
- sendFile()
- sendStatus()
- set()
- status()
- statusCode
- type()
- vary()
- setHeader()
- removeHeader()
- setHeadersSent()
- setLocals()
- resetMocked()
- Router
Other
express()
How to setup Application to use in Jest:
1jest.mock('express', () => { 2 return require('jest-express'); 3});
express.json()
Ways to use this API:
1expect(express.json).toHaveBeenCalledWith([options]);
express.static()
Ways to use this API:
1expect(express.static).toHaveBeenCalledWith(root, [options]);
express.Router()
Ways to use this API:
1expect(express.Router).toHaveBeenCalledWith([options]);
express.urlencoded()
Ways to use this API:
1expect(express.urlencoded).toHaveBeenCalledWith([options]);
Application
How to setup Application to use in Jest:
1import { Express } from 'jest-express/lib/express'; 2import { server } from '../src/server.js'; 3 4let app; 5 6describe('Server', () => { 7 beforeEach(() => { 8 app = new Express(); 9 }); 10 11 afterEach(() => { 12 app.resetMocked(); 13 }); 14 15 test('should setup server', () => { 16 const options = { 17 port: 3000, 18 }; 19 20 server(app, options); 21 22 expect(app.set).toBeCalledWith('port', options.port); 23 }); 24});
app.locals
Ways to use this API:
Setup:
1beforeEach(() => { 2 app = new Express(); 3 app.setLocals('title', 'My App'); 4});
app.mountpath
Ways to use this API:
Setup:
1beforeEach(() => { 2 app = new Express(); 3 app.setMountPath('/admin'); 4});
app.all()
Ways to use this API:
1expect(app.all).toBeCalledWith(path, callback [, callback ...]);
app.get()
Ways to use this API:
1expect(app.get).toBeCalledWith(path, callback [, callback ...]);
app.head()
Ways to use this API:
1expect(app.head).toBeCalledWith(path, callback [, callback ...]);
app.post()
Ways to use this API:
1expect(app.post).toBeCalledWith(path, callback [, callback ...]);
app.put()
Ways to use this API:
1expect(app.put).toBeCalledWith(path, callback [, callback ...]);
app.delete()
Ways to use this API:
1expect(app.delete).toBeCalledWith(path, callback [, callback ...]);
app.connect()
Ways to use this API:
1expect(app.connect).toBeCalledWith(path, callback [, callback ...]);
app.options()
Ways to use this API:
1expect(app.options).toBeCalledWith(path, callback [, callback ...]);
app.trace()
Ways to use this API:
1expect(app.trace).toBeCalledWith(path, callback [, callback ...]);
app.patch()
Ways to use this API:
1expect(app.patch).toBeCalledWith(path, callback [, callback ...]);
app.param()
Ways to use this API:
1expect(app.param).toBeCalledWith([name], callback);
app.render()
Ways to use this API:
1expect(app.param).toBeCalledWith(view, [locals], callback);
app.use()
Ways to use this API:
1expect(app.use).toBeCalledWith([path,] callback [, callback...]);
Request
How to setup Request to use in Jest:
1import { Request } from 'jest-express/lib/request'; 2import { endpoint } from '../src/endpoint.js'; 3 4let request; 5 6describe('Endpoint', () => { 7 beforeEach(() => { 8 request = new Request('/users?sort=desc', { 9 headers: { 10 Accept: 'text/html' 11 } 12 }); 13 }); 14 15 afterEach(() => { 16 request.resetMocked(); 17 }); 18 19 test('should setup endpoint', () => { 20 endpoint(request); 21 22 expect(request).toBeCalled(); 23 }); 24});
request.baseUrl
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setBaseUrl(baseUrl); 4});
request.body
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setBody(body); 4});
request.cookies
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setCookies(cookies); 4});
request.fresh
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setFresh(boolean); 4});
request.hostname
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setHostname(string); 4});
request.setHeaders
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setHeaders("X-Custom-Header", "foo"); 4}); 5 6// or 7 8beforeEach(() => { 9 request = new Request(); 10 request.setHeaders({ 11 "X-Custom-Header", "foo", 12 "X-Custom-Header-2", "bar" 13 }); 14}); 15
request.ip
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setIp(ip); 4});
request.ips
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setIps(ips); 4});
request.method
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setMethod(method); 4});
request.originalUrl
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setOriginalUrl(originalUrl); 4});
request.params
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setParams(params); 4});
request.path
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setPath(path); 4});
request.protocol
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setProtocol(protocol); 4});
request.query
You can use it by passing key value pair:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setQuery('Accept', 'text/html'); 4});
Or by passing an object:
1beforeEach(() => { 2 request = new Request(); 3 request.setQuery({ 'Accept': 'text/html', 'Accept-Language': 'en' }); 4});
request.route
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setRoute(route); 4});
request.secure
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setSecure(secure); 4});
request.signedCookies
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setSignedCookies(signedCookies); 4});
request.stale
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setStale(boolean); 4});
request.subdomains
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setSubdomains(subdomains); 4});
request.xhr
Ways to use this API:
Setup:
1beforeEach(() => { 2 request = new Request(); 3 request.setXhr(boolean); 4});
request.accepts()
Ways to use this API:
1expect(request.accepts).toBeCalledWith(types);
request.acceptsCharsets()
Ways to use this API:
1expect(request.acceptsCharsets).toBeCalledWith(charset [, ...]);
request.acceptsEncodings()
Ways to use this API:
1expect(request.acceptsEncodings).toBeCalledWith(encoding [, ...]);
request.acceptsLanguages()
Ways to use this API:
1expect(request.acceptsLanguages).toBeCalledWith(lang [, ...]);
request.get()
Ways to use this API:
1expect(request.get).toBeCalledWith(field);
request.is()
Ways to use this API:
1expect(request.is).toBeCalledWith(type);
request.param()
Ways to use this API:
1expect(request.param).toBeCalledWith(name [, defaultValue]);
request.range()
Ways to use this API:
1expect(request.range).toBeCalledWith(size[, options]);
Response
How to setup Response to use in Jest:
1import { Response } from 'jest-express/lib/response'; 2import { endpoint } from '../src/endpoint.js'; 3 4let response; 5 6describe('Endpoint', () => { 7 beforeEach(() => { 8 response = new Response(); 9 }); 10 11 afterEach(() => { 12 response.resetMocked(); 13 }); 14 15 test('should setup endpoint', () => { 16 endpoint(response); 17 18 expect(response).toBeCalled(); 19 }); 20});
response.setHeader
Ways to use this API:
Setup:
1beforeEach(() => {
2 response = new Response();
3 response.setHeader(key, value);
4 expect(response.setHeader).toBeCalledWith(key, value);
5});
response.removeHeader
Ways to use this API:
Setup:
1beforeEach(() => { 2 response = new Response(); 3 response.removeHeader(key); 4 expect(response.removeHeader).toBeCalledWith(key); 5});
response.headersSent
Ways to use this API:
Setup:
1beforeEach(() => { 2 response = new Response(); 3 response.setHeadersSent(boolean); 4});
response.locals
Ways to use this API:
Setup:
1beforeEach(() => { 2 response = new Response(); 3 response.setLocals('title', 'My App'); 4});
response.append()
Ways to use this API:
1expect(response.append).toBeCalledWith(field [, value]);
response.attachment()
Ways to use this API:
1expect(response.attachment).toBeCalledWith([filename]);
reponse.body
Ways to use this API:
1expect(response.body).toEqual(value);
response.cookie()
Ways to use this API:
1expect(response.cookie).toBeCalledWith(name, value [, options]);
response.clearCookie()
Ways to use this API:
1expect(response.clearCookie).toBeCalledWith(name [, options]);
response.download()
Ways to use this API:
1expect(response.download).toBeCalledWith(path [, filename] [, options] [, fn]);
response.end()
Ways to use this API:
1expect(response.end).toBeCalledWith([data] [, encoding]);
response.format()
Ways to use this API:
1expect(response.format).toBeCalledWith(object);
response.get()
Ways to use this API:
1expect(response.get).toBeCalledWith(field);
response.getHeader()
Ways to use this API:
1response.setHeader('Accept', 'text/html') 2expect(response.getHeader('Accept')).toEqual('text/html');
response.header()
An alias for response.set()
1expect(response.header).toBeCalledWith(field, [value]);
response.json()
Ways to use this API:
1expect(response.json).toBeCalledWith([body]);
response.jsonp()
Ways to use this API:
1expect(response.jsonp).toBeCalledWith([body]);
response.links()
Ways to use this API:
1expect(response.links).toBeCalledWith(links);
response.location()
Ways to use this API:
1expect(response.location).toBeCalledWith(path);
response.redirect()
Ways to use this API:
1expect(response.redirect).toBeCalledWith([status,] path);
response.render()
Ways to use this API:
1expect(response.render).toBeCalledWith(view [, locals] [, callback]);
response.send()
Ways to use this API:
1expect(response.send).toBeCalledWith([body]);
response.sendFile()
Ways to use this API:
1expect(response.sendFile).toBeCalledWith(path [, options] [, fn]);
response.sendStatus()
Ways to use this API:
1expect(response.sendStatus).toBeCalledWith(statusCode);
response.set()
Sets headers. It is calling response.setHeader()
internally.
1expect(response.set).toBeCalledWith(field [, value]);
response.status()
Ways to use this API:
1expect(response.status).toBeCalledWith(code);
response.statusCode
ways to use this API:
1expect(response.statusCode).toEqual(code);
response.type()
Ways to use this API:
1expect(response.type).toBeCalledWith(type);
response.vary()
Ways to use this API:
1expect(response.vary).toBeCalledWith(field);
Router
How to setup Response to use in Jest:
1import { Router } from 'jest-express/lib/router'; 2import { endpoint } from '../src/endpoint.js'; 3 4let router; 5 6describe('Endpoint', () => { 7 beforeEach(() => { 8 router = new Router(); 9 }); 10 11 afterEach(() => { 12 router.resetMocked(); 13 }); 14 15 test('should setup endpoint', () => { 16 endpoint(router); 17 18 expect(router).toBeCalled(); 19 }); 20});
router.all()
Ways to use this API:
1expect(router.all).toBeCalledWith(path, [callback, ...] callback);
router.get()
Ways to use this API:
1expect(router.get).toBeCalledWith(path, [callback, ...] callback);
router.param()
Ways to use this API:
1expect(router.param).toBeCalledWith(name, callback);
router.route()
Ways to use this API:
1expect(router.route).toBeCalledWith(path);
router.use()
Ways to use this API:
1expect(router.use).toBeCalledWith([path], [function, ...] function);
resetMocked()
Resets all information stored in the mock, including any initial implementation and mock name given.
This is useful when you want to completely restore a mock back to its initial state.
Development
Setup
1$ git clone git@github.com:jameswlane/jest-express.git 2$ cd jest-express 3$ npm install
Tests
Linters:
1$ npm run tslint
Tests:
1$ npm test
Contributing
License
Contributors
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Warn: no linked content found
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:54: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/jest-express/jest-express/npm-publish.yml/master?enable=pin
- Info: 0 out of 10 GitHub-owned GitHubAction dependencies pinned
- Info: 4 out of 4 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
12 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-5w9c-rv96-fr7g
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-f9xv-q969-pqx4
Score
3.2
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to jest-express
@jest-mock/express
A lightweight Jest mock for unit testing Express
@nx/express
The Nx Plugin for Express contains executors and generators for allowing your workspace to create powerful Express Node applications and APIs.
@nrwl/express
The Nx Plugin for Express contains executors and generators for allowing your workspace to create powerful Express Node applications and APIs.
@gasbuddy/service
An opinionated framework for building configuration driven services - web, api, or job. Uses swagger, pino logging, express, confit, Typescript and Jest.