Socket
Socket
Sign inDemoInstall

stubs

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

4

index.js

@@ -1,2 +0,2 @@

'use strict';
'use strict'

@@ -28,3 +28,3 @@ module.exports = function stubs(obj, method, cfg, stub) {

stub.apply(obj, args)
returnVal = stub.apply(obj, args) || returnVal

@@ -31,0 +31,0 @@ if (!norevert && --cfg.calls === 0)

{
"name": "stubs",
"version": "2.0.0",
"version": "3.0.0",
"description": "Easy method stubber.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,2 +0,2 @@

'use strict';
'use strict'

@@ -57,2 +57,15 @@ var assert = require('assert')

it('returns value of overridden method call', function() {
var overriddenUniqueVal = {}
var obj = {}
obj.method = function() {}
stubs(obj, 'method', { callthrough: true }, function() {
return overriddenUniqueVal
})
assert.strictEqual(obj.method(), overriddenUniqueVal)
})
it('calls through to original method', function() {

@@ -89,2 +102,36 @@ var originalCalled = false

it('returns calls override and returns original value', function() {
var uniqueVal = {}
var overrideWasCalled = false
var obj = {}
obj.method = function() {
return uniqueVal
}
stubs(obj, 'method', { callthrough: true }, function() {
// does not return anything
overrideWasCalled = true
})
assert.strictEqual(obj.method(), uniqueVal)
assert.strictEqual(overrideWasCalled, true)
})
it('returns value of overridden method call', function() {
var uniqueVal = {}
var overriddenUniqueVal = {}
var obj = {}
obj.method = function() {
return uniqueVal
}
stubs(obj, 'method', { callthrough: true }, function() {
return overriddenUniqueVal
})
assert.strictEqual(obj.method(), overriddenUniqueVal)
})
it('stops calling stub after n calls', function() {

@@ -91,0 +138,0 @@ var timesToCall = 5

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc