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:
jest;
express.json()
Ways to use this API:
;
express.static()
Ways to use this API:
;
express.Router()
Ways to use this API:
;
express.urlencoded()
Ways to use this API:
;
Application
How to setup Application to use in Jest:
;; let app; ;
app.locals
Ways to use this API:
Setup:
;
app.mountpath
Ways to use this API:
Setup:
;
app.all()
Ways to use this API:
;
app.get()
Ways to use this API:
;
app.head()
Ways to use this API:
;
app.post()
Ways to use this API:
;
app.put()
Ways to use this API:
;
app.delete()
Ways to use this API:
;
app.connect()
Ways to use this API:
;
app.options()
Ways to use this API:
;
app.trace()
Ways to use this API:
;
app.patch()
Ways to use this API:
;
app.param()
Ways to use this API:
;
app.render()
Ways to use this API:
;
app.use()
Ways to use this API:
;
Request
How to setup Request to use in Jest:
;; let request; ;
request.baseUrl
Ways to use this API:
Setup:
;
request.body
Ways to use this API:
Setup:
;
request.cookies
Ways to use this API:
Setup:
;
request.fresh
Ways to use this API:
Setup:
;
request.hostname
Ways to use this API:
Setup:
;
request.setHeaders
Ways to use this API:
Setup:
; // or ;
request.ip
Ways to use this API:
Setup:
;
request.ips
Ways to use this API:
Setup:
;
request.method
Ways to use this API:
Setup:
;
request.originalUrl
Ways to use this API:
Setup:
;
request.params
Ways to use this API:
Setup:
;
request.path
Ways to use this API:
Setup:
;
request.protocol
Ways to use this API:
Setup:
;
request.query
You can use it by passing key value pair:
Setup:
;
Or by passing an object:
;
request.route
Ways to use this API:
Setup:
;
request.secure
Ways to use this API:
Setup:
;
request.signedCookies
Ways to use this API:
Setup:
;
request.stale
Ways to use this API:
Setup:
;
request.subdomains
Ways to use this API:
Setup:
;
request.xhr
Ways to use this API:
Setup:
;
request.accepts()
Ways to use this API:
;
request.acceptsCharsets()
Ways to use this API:
;
request.acceptsEncodings()
Ways to use this API:
;
request.acceptsLanguages()
Ways to use this API:
;
request.get()
Ways to use this API:
;
request.is()
Ways to use this API:
;
request.param()
Ways to use this API:
;
request.range()
Ways to use this API:
;
Response
How to setup Response to use in Jest:
;; let response; ;
response.setHeader
Ways to use this API:
Setup:
;
response.removeHeader
Ways to use this API:
Setup:
;
response.headersSent
Ways to use this API:
Setup:
;
response.locals
Ways to use this API:
Setup:
;
response.append()
Ways to use this API:
;
response.attachment()
Ways to use this API:
;
reponse.body
Ways to use this API:
;
response.cookie()
Ways to use this API:
;
response.clearCookie()
Ways to use this API:
;
response.download()
Ways to use this API:
;
response.end()
Ways to use this API:
;
response.format()
Ways to use this API:
;
response.get()
Ways to use this API:
;
response.getHeader()
Ways to use this API:
response;
response.header()
An alias for response.set()
;
response.json()
Ways to use this API:
;
response.jsonp()
Ways to use this API:
;
response.links()
Ways to use this API:
;
response.location()
Ways to use this API:
;
response.redirect()
Ways to use this API:
;
response.render()
Ways to use this API:
;
response.send()
Ways to use this API:
;
response.sendFile()
Ways to use this API:
;
response.sendStatus()
Ways to use this API:
;
response.set()
Sets headers. It is calling response.setHeader()
internally.
;
response.status()
Ways to use this API:
;
response.statusCode
ways to use this API:
;
response.type()
Ways to use this API:
;
response.vary()
Ways to use this API:
;
Router
How to setup Response to use in Jest:
;; let router; ;
router.all()
Ways to use this API:
;
router.get()
Ways to use this API:
;
router.param()
Ways to use this API:
;
router.route()
Ways to use this API:
;
router.use()
Ways to use this API:
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
$ git clone git@github.com:jameswlane/jest-express.git$ cd jest-express$ npm install
Tests
Linters:
$ npm run tslint
Tests:
$ 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!