@jest-mock/express
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -30,3 +30,3 @@ "use strict"; | ||
// http - ServerResponse | ||
assignSocket: jest.fn(), detachSocket: jest.fn(), writeContinue: jest.fn(), writeHead: jest.fn(), writeProcessing: jest.fn(), statusCode, | ||
end: jest.fn(), assignSocket: jest.fn(), detachSocket: jest.fn(), writeContinue: jest.fn(), writeHead: jest.fn(), writeProcessing: jest.fn(), statusCode, | ||
statusMessage, | ||
@@ -91,2 +91,3 @@ // http - OutgoingMessage | ||
// http - ServerResponse | ||
response.end.mockClear(); | ||
response.assignSocket.mockClear(); | ||
@@ -93,0 +94,0 @@ response.detachSocket.mockClear(); |
@@ -8,3 +8,3 @@ "use strict"; | ||
const response_1 = __importDefault(require("./response")); | ||
const DEFAULT_RES_KEY_LENGTH = 52; | ||
const DEFAULT_RES_KEY_LENGTH = 53; | ||
describe('getMockRes', () => { | ||
@@ -47,2 +47,3 @@ test('returns expected object', () => { | ||
// http - ServerResponse | ||
expect(typeof res.end).toBe('function'); | ||
expect(typeof res.assignSocket).toBe('function'); | ||
@@ -303,2 +304,3 @@ expect(typeof res.detachSocket).toBe('function'); | ||
// http - ServerResponse | ||
expect(res.end).toBeCalledTimes(1); | ||
expect(res.assignSocket).toBeCalledTimes(1); | ||
@@ -349,2 +351,3 @@ expect(res.detachSocket).toBeCalledTimes(1); | ||
// http - ServerResponse | ||
expect(res.end).not.toBeCalled(); | ||
expect(res.assignSocket).not.toBeCalled(); | ||
@@ -398,2 +401,3 @@ expect(res.detachSocket).not.toBeCalled(); | ||
// http - ServerResponse | ||
expect(res.end).toBeCalledTimes(1); | ||
expect(res.assignSocket).toBeCalledTimes(1); | ||
@@ -444,2 +448,3 @@ expect(res.detachSocket).toBeCalledTimes(1); | ||
// http - ServerResponse | ||
expect(res.end).not.toBeCalled(); | ||
expect(res.assignSocket).not.toBeCalled(); | ||
@@ -461,2 +466,13 @@ expect(res.detachSocket).not.toBeCalled(); | ||
}); | ||
test('issue #32', () => { | ||
const statusCode = 404; | ||
const { res } = response_1.default(); | ||
res.status(statusCode).end(); | ||
// status is called | ||
expect(res.status).toBeCalledTimes(1); | ||
expect(res.status).toBeCalledWith(statusCode); | ||
// chained end is called | ||
expect(res.end).toBeCalledTimes(1); | ||
expect(res.end).toBeCalledWith(); | ||
}); | ||
}); | ||
@@ -489,2 +505,3 @@ function callAll(res) { | ||
// http - ServerResponse | ||
res.end(); | ||
res.assignSocket({}); | ||
@@ -491,0 +508,0 @@ res.detachSocket({}); |
{ | ||
"name": "@jest-mock/express", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "A lightweight Jest mock for unit testing Express", | ||
@@ -44,12 +44,12 @@ "main": "dist/index.js", | ||
"@types/express": "^4.17.9", | ||
"@types/jest": "^26.0.19", | ||
"@typescript-eslint/eslint-plugin": "^4.9.1", | ||
"@typescript-eslint/parser": "^4.9.1", | ||
"@types/jest": "^26.0.20", | ||
"@typescript-eslint/eslint-plugin": "^4.12.0", | ||
"@typescript-eslint/parser": "^4.12.0", | ||
"coveralls": "^3.0.7", | ||
"eslint": "^7.15.0", | ||
"eslint-config-prettier": "^7.0.0", | ||
"eslint-plugin-prettier": "^3.2.0", | ||
"eslint": "^7.17.0", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"snyk": "^1.436.0", | ||
"snyk": "^1.437.3", | ||
"ts-jest": "^26.4.4", | ||
@@ -56,0 +56,0 @@ "typescript": "^4.1.3" |
@@ -8,3 +8,3 @@ // Types | ||
const DEFAULT_RES_KEY_LENGTH = 52 | ||
const DEFAULT_RES_KEY_LENGTH = 53 | ||
@@ -51,2 +51,3 @@ describe('getMockRes', () => { | ||
// http - ServerResponse | ||
expect(typeof res.end).toBe('function') | ||
expect(typeof res.assignSocket).toBe('function') | ||
@@ -389,2 +390,3 @@ expect(typeof res.detachSocket).toBe('function') | ||
// http - ServerResponse | ||
expect(res.end as jest.Mock).toBeCalledTimes(1) | ||
expect(res.assignSocket as jest.Mock).toBeCalledTimes(1) | ||
@@ -437,2 +439,3 @@ expect(res.detachSocket as jest.Mock).toBeCalledTimes(1) | ||
// http - ServerResponse | ||
expect(res.end as jest.Mock).not.toBeCalled() | ||
expect(res.assignSocket as jest.Mock).not.toBeCalled() | ||
@@ -489,2 +492,3 @@ expect(res.detachSocket as jest.Mock).not.toBeCalled() | ||
// http - ServerResponse | ||
expect(res.end as jest.Mock).toBeCalledTimes(1) | ||
expect(res.assignSocket as jest.Mock).toBeCalledTimes(1) | ||
@@ -537,2 +541,3 @@ expect(res.detachSocket as jest.Mock).toBeCalledTimes(1) | ||
// http - ServerResponse | ||
expect(res.end as jest.Mock).not.toBeCalled() | ||
expect(res.assignSocket as jest.Mock).not.toBeCalled() | ||
@@ -554,2 +559,16 @@ expect(res.detachSocket as jest.Mock).not.toBeCalled() | ||
}) | ||
test('issue #32', () => { | ||
const statusCode = 404 | ||
const { res } = getMockRes() | ||
res.status(statusCode).end() | ||
// status is called | ||
expect(res.status).toBeCalledTimes(1) | ||
expect(res.status).toBeCalledWith(statusCode) | ||
// chained end is called | ||
expect(res.end).toBeCalledTimes(1) | ||
expect(res.end).toBeCalledWith() | ||
}) | ||
}) | ||
@@ -583,2 +602,3 @@ | ||
// http - ServerResponse | ||
res.end() | ||
res.assignSocket({} as Socket) | ||
@@ -585,0 +605,0 @@ res.detachSocket({} as Socket) |
@@ -69,2 +69,3 @@ // Libraries | ||
// http - ServerResponse | ||
end: jest.fn(), | ||
assignSocket: jest.fn(), | ||
@@ -149,2 +150,3 @@ detachSocket: jest.fn(), | ||
// http - ServerResponse | ||
response.end.mockClear() | ||
response.assignSocket.mockClear() | ||
@@ -151,0 +153,0 @@ response.detachSocket.mockClear() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
345208
2246