Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jest-mock/express

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jest-mock/express - npm Package Compare versions

Comparing version 1.1.0 to 1.1.2

.github/workflows/npm-publish.yml

2

jest.config.js
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
testEnvironment: 'node',
}
{
"name": "@jest-mock/express",
"version": "1.1.0",
"version": "1.1.2",
"description": "A lightweight Jest mock for unit testing Express",

@@ -8,4 +8,2 @@ "main": "dist/index.js",

"scripts": {
"build": "tsc",
"clean": "rm -rf dist/*",
"test": "jest --coverage",

@@ -15,3 +13,6 @@ "test-watch": "jest \"/*.ts\" --watchAll",

"test-coverage": "yarn test && cat ./coverage/lcov.info | coveralls",
"lint": "tsc --noEmit && eslint '*/**/*.{js,ts}' --quiet --fix"
"lint": "tsc --noEmit && eslint '*/**/*.{js,ts}' --quiet --fix",
"build": "tsc",
"clean": "rm -rf dist/*",
"release": "yarn && yarn clean && yarn build && yarn test"
},

@@ -29,2 +30,4 @@ "repository": {

"express",
"expressjs",
"controller",
"typescript"

@@ -31,0 +34,0 @@ ],

@@ -28,3 +28,3 @@ # @jest-mock/express

### `getMockReq`
### Request - `getMockReq`

@@ -37,3 +37,3 @@ `getMockReq` is intended to mock the `req` object as easily as possible. In its simplest form you can call it with no arguments to return a standard `req` with no values.

To create mock requests with values you can just provide them to the function in any order and all are optional. The advantage of this is that it ensures all of the other properties are not undefined.
To create mock requests with values, you can simply provide them to the function in any order with all being optional. The advantage of this is that it ensures all of the other properties are not undefined.

@@ -49,9 +49,9 @@ ```typescript

params: { id: 564 },
body: { firstname: 'James', lastname: 'Smith', age: 34 }
body: { firstname: 'James', lastname: 'Smith', age: 34 },
})
```
### `getMockRes`
### Response - `getMockRes`
`getMockRes` will provide a mocked `res` object with mock functions. Chaining has been implemented for the required functions.
`getMockRes` will provide a `res` object with Jest mock functions. Chaining has been implemented for the applicable functions.

@@ -72,4 +72,8 @@ ```typescript

It will also provide a mock `next` function for convenience, that will also be cleared as part of `mockClear`/`clearMockRes`.
It will also provide a mock `next` function for convenience. That will also be cleared as part of the call to `mockClear`/`clearMockRes`.
### Example
A full example could be:
```typescript

@@ -82,9 +86,9 @@ const { res, next } = getMockRes()

// provide the mock res and next to check against
await myController.get(req, res, next)
// provide the mock req, res, and next to check against
await myController.getEntity(req, res, next)
expect(res.json).toHaveBeenCalledWith(
expect.objectContaining({
id: 'abc-def'
})
id: 'abc-def',
}),
)

@@ -94,29 +98,1 @@ expect(next).toBeCalled()

```
## Available Scripts
In the project directory, you can run:
### `yarn build`
Transpiles the TypeScript source to the `dist` folder.
### `yarn clean`
Clears the `dist` folder.
### `yarn test`
Runs the tests and produces the coverage output.
### `yarn test-watch`
Runs the tests in watch mode, will not test the dist output folder.
### `test-watch-all`
Runs the tests in watch mode, will test both the TypeScript and generated JavaScript.
### `yarn lint`
Runs the linter over the project.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc