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

mini-mock

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-mock - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

test/lib/voice-widget-class.js

40

lib/mocker.js

@@ -52,3 +52,28 @@ /**

var mock = Object.assign({}, this.__currentProto);
var self = this;
var mock = {};
if (Object.keys(this.__currentProto).length > 0)
mock = Object.assign({}, this.__currentProto);
else {
// create a mixin
Object.getOwnPropertyNames(this.__currentProto).forEach(function (key) {
if (key != 'constructor') {
var descriptor = Object.getOwnPropertyDescriptor(self.__currentProto, key);
//var funcBody = descriptor.value.toString().match(/[^{]+\{([\s\S]*)\}$/)[1];
//var func = new Function(funcBody);
Object.defineProperty(mock, key, {
value: descriptor.value,
enumerable: true,
configurable: true,
writeable: true
});
}
});
}
mock.recorder = {};

@@ -59,2 +84,5 @@

// remove the original...
delete mock[x.name];
mock.recorder[x.name] = {

@@ -79,8 +107,12 @@ calls: 0

return cbFunc.apply(undefined, x.expectedCbArgs);
};
}
});
this.__mockedPromiseFuncs.forEach((x) => {
if (!mock[x.name]) throw new Error('Function not found!');
// remove the original...
delete mock[x.name];
mock.recorder[x.name] = {

@@ -112,2 +144,3 @@ calls: 0

};
});

@@ -118,2 +151,5 @@

// remove the original...
delete mock[x.name];
mock.recorder[x.name] = {

@@ -120,0 +156,0 @@ calls: 0

2

package.json
{
"name": "mini-mock",
"version": "0.2.2",
"version": "0.3.0",
"description": "An ultra-lightweight mocking framework for Node",

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

@@ -10,2 +10,3 @@ /**

var VoiceWidget = require('./lib/voice-widget');
var VoiceWidgetClass = require('./lib/voice-widget-class');
var WidgetFactory = require('./lib/widget-factory');

@@ -40,2 +41,6 @@

this.__voiceWidgetClass = mocker.mock(VoiceWidgetClass.prototype)
.withPromiseStub('speak', 'Wobble wobble!', null, null) // promise will resolve with 'Wobble wobble!'
.create();
this.__widgetFactory = mocker.mock(WidgetFactory.prototype)

@@ -73,2 +78,14 @@ .withSyncStub('getVoiceWidget', this.__voiceWidget)

it('mock class promise function returns correct result', function (done) {
this.__voiceWidgetClass.speak()
.then((result) => {
expect(result).to.equal('Wobble wobble!');
done();
})
.catch((err)=> {
done(err);
});
});
it('mock asynchronous function with delay returns correct result', function (done) {

@@ -136,2 +153,3 @@

});
});
})
;
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