New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-when

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-when - npm Package Compare versions

Comparing version 2.5.0 to 2.6.0

15

package.json
{
"name": "jest-when",
"version": "2.5.0",
"version": "2.6.0",
"description": "An extension lib for jest",

@@ -23,3 +23,3 @@ "license": "MIT",

"bunyan": "^1.8.12",
"expect": "^22.4.3"
"expect": "^24.8.0"
},

@@ -33,9 +33,8 @@ "devDependencies": {

"eslint-plugin-standard": "^3.1.0",
"jest": "^22.1.1",
"jest": "^24.8.0",
"pre-commit": "^1.2.2",
"stryker": "^0.24.0",
"stryker-api": "^0.17.1",
"stryker-html-reporter": "^0.14.1",
"stryker-javascript-mutator": "^0.7.1",
"stryker-jest-runner": "^0.7.0"
"@stryker-mutator/core": "^2.0.0",
"@stryker-mutator/html-reporter": "^2.0.0",
"@stryker-mutator/javascript-mutator": "^2.0.0",
"@stryker-mutator/jest-runner": "^2.0.0"
},

@@ -42,0 +41,0 @@ "jest": {

@@ -131,2 +131,12 @@ # jest-when

#### Supports jest.spyOn:
```javascript
const theSpiedMethod = jest.spyOn(theInstance, 'theMethod');
when(theSpiedMethod)
.calledWith(1)
.mockReturnValue('mock');
const returnValue = theInstance.theMethod(1);
expect(returnValue).toBe('mock');
```
#### Supports jest matchers:

@@ -133,0 +143,0 @@ ```javascript

const assert = require('assert')
const utils = require('expect/build/jasmine_utils')
const utils = require('expect/build/jasmineUtils')
const logger = require('./log')('when')

@@ -35,2 +35,3 @@

this.callMocks = []
this._origMock = fn.getMockImplementation()

@@ -103,2 +104,8 @@ if (defaultValue.isSet) {

this.expectCalledWith = (...matchers) => ({ ...mockFunctions(matchers, true) })
this.resetWhenMocks = () => {
fn.mockImplementation(fn.__whenMock__._origMock)
fn.__whenMock__ = undefined
registry.delete(fn)
}
}

@@ -116,2 +123,3 @@ }

registry.forEach(fn => {
fn.mockImplementation(fn.__whenMock__._origMock)
fn.__whenMock__ = undefined

@@ -118,0 +126,0 @@ })

const { stringContaining } = expect
const errMsg = ({ expect, actual }) =>
new RegExp(`Expected.*\\n.*${expect}.*\\nReceived.*\\n.*${actual}`)
new RegExp(`Expected.*${expect}.*\\nReceived.*${actual}`)

@@ -10,3 +10,3 @@ describe('When', () => {

beforeEach(() => {
spyEquals = jest.spyOn(require('expect/build/jasmine_utils'), 'equals')
spyEquals = jest.spyOn(require('expect/build/jasmineUtils'), 'equals')

@@ -66,2 +66,22 @@ mockLogger = {

it('reset of mocks restores original implementation', () => {
const fn = jest.fn(() => 'a')
when(fn).expectCalledWith(1).mockReturnValueOnce('x')
resetAllWhenMocks()
expect(fn(1)).toEqual('a')
})
it('allows reset of mocks for one function', () => {
const fn = jest.fn(() => 'a')
const mock = when(fn).expectCalledWith(1).mockReturnValueOnce('x')
mock.resetWhenMocks()
expect(fn(1)).toEqual('a')
})
it('allows checking that all mocks were called', () => {

@@ -501,3 +521,20 @@ const fn1 = jest.fn()

})
it('accepts a spied method:', () => {
class TheClass {
theMethod (theArgument) {
return 'real'
}
}
const theInstance = new TheClass()
const theSpiedMethod = jest.spyOn(theInstance, 'theMethod')
when(theSpiedMethod)
.calledWith(1)
.mockReturnValue('mock')
const returnValue = theInstance.theMethod(1)
expect(returnValue).toBe('mock')
})
})
})

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