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

@salestrip/stub

Package Overview
Dependencies
Maintainers
6
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salestrip/stub - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

.editorconfig

11

lib/stub.js

@@ -0,3 +1,10 @@

/* eslint no-empty-function: 'off' */
'use strict'
// 3rd-party
const Bluebird = require('bluebird')
// init
Bluebird.onPossiblyUnhandledRejection(() => {})
module.exports = function(subject, methodName, value) {

@@ -12,6 +19,6 @@ subject[`_${methodName}`] = subject[methodName]

subject[methodName].resolves = function(results) {
subject[methodName].mockResolvedValue(results)
subject[methodName].mockReturnValue(Bluebird.resolve(results))
}
subject[methodName].rejects = function(results) {
subject[methodName].mockRejectedValue(results)
subject[methodName].mockReturnValue(Bluebird.reject(results))
}

@@ -18,0 +25,0 @@ subject[methodName].returns = function(results) {

6

package.json

@@ -6,3 +6,3 @@ {

"license": "MIT",
"version": "1.0.0",
"version": "2.0.0",
"main": "index.js",

@@ -28,3 +28,5 @@ "author": "SalesTrip Limited",

],
"dependencies": {},
"dependencies": {
"bluebird": "^3.5.2"
},
"devDependencies": {

@@ -31,0 +33,0 @@ "@salestrip/eslint-config": "^0.4.0",

@@ -7,3 +7,3 @@ # @salestrip/stub

## Installation
## Install

@@ -14,4 +14,39 @@ ```bash

## Releasing
## Usage
```js
const stub = require('@salestrip/stub')
const fooService = require('services/foo.service')
beforeEach(() => {
stub(fooService, 'method')
})
afterEach(() => {
fooService.method.restore()
})
it('resolves', () => {
fooService.method.resolves('value')
expect(fooService.method()).resolves.toBe('value')
})
it('rejects', () => {
fooService.method.rejects('value')
expect(fooService.method()).rejects.toBe('value')
})
it('returns', () => {
fooService.method.returns('value')
expect(fooService.method()).toBe('value')
})
it('throws', () => {
fooService.method.throws(new Error('value'))
expect(fooService.method()).toThrow('value')
})
```
## Release
To release a new version, use npm. Using `npm version` will update the version in `package.json` before committing the resulting file change to git and adding the appropriate git tag. Pushing a tagged version to `origin` will trigger a CI deployment to the npm registry.

@@ -41,1 +76,2 @@

git push --tags
```
'use strict'
// 3rd-party
const Bluebird = require('bluebird')
// local

@@ -45,2 +48,8 @@ const stub = require('../lib/stub')

})
it('returns Bluebird promise', () => {
const {subject} = this
subject.method.resolves('whatever')
expect(subject.method()).toBeInstanceOf(Bluebird)
})
})

@@ -47,0 +56,0 @@

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