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.1.0 to 0.2.0

13

lib/mocker.js

@@ -28,6 +28,7 @@ /**

Mocker.prototype.withAsyncStub = function (funcName, expectedCallbackArgs) {
Mocker.prototype.withAsyncStub = function (funcName, expectedCallbackArgs, delay) {
this.__mockedAsyncFuncs.push({
name: funcName,
expectedCbArgs: expectedCallbackArgs
expectedCbArgs: expectedCallbackArgs,
delay: delay
});

@@ -57,3 +58,9 @@ return this;

var cbFunc = arguments[argCount];
return cbFunc.apply(undefined, x.expectedCbArgs);
if (x.delay != null) {
setTimeout(function () {
return cbFunc.apply(undefined, x.expectedCbArgs);
}, x.delay)
}else
return cbFunc.apply(undefined, x.expectedCbArgs);
};

@@ -60,0 +67,0 @@ });

{
"name": "mini-mock",
"version": "0.1.0",
"version": "0.2.0",
"description": "An ultra-lightweight mocking framework for Node",

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

@@ -20,2 +20,6 @@ /**

this.__motorWithDelay = mocker.mock(Motor.prototype)
.withAsyncStub('start', [null, 250], 1500) // callback args are [null, 250]
.create();
this.__motorFactory = mocker.mock(MotorFactory.prototype)

@@ -25,2 +29,6 @@ .withSyncStub('getMotor', this.__motor)

this.__motorFactoryWithDelay = mocker.mock(MotorFactory.prototype)
.withSyncStub('getMotor', this.__motorWithDelay)
.create();
done();

@@ -44,2 +52,23 @@ });

it('mock asynchronous function with delay returns correct result', function (done) {
var robot = new Robot(this.__motorFactoryWithDelay);
var start = Date.now();
robot.walk(function (e, result) {
if (e)
return done(e);
var end = Date.now();
var timeDiff = end - start;
expect(timeDiff).to.be.greaterThan(1000);
expect(result).to.equal(250);
done();
})
});
it('mock synchronous function returns correct result', function (done) {

@@ -46,0 +75,0 @@

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