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

deride

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deride - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

23

lib/deride.js

@@ -144,7 +144,19 @@ /*

function toCallbackWith(args){
var func = function(){
for(var i = 0; i < arguments.length;i++){
function toTimeWarp(milliseconds) {
var func = function() {
var originalTimeoutFunc = setTimeout;
setTimeout = function(delegate, timeout){
originalTimeoutFunc(delegate, timeout - milliseconds);
};
var result = originalMethod.apply(obj, arguments);
return result;
};
checkArgumentsToInvoke(func);
}
function toCallbackWith(args) {
var func = function() {
for (var i = 0; i < arguments.length; i++) {
var argType = typeof(arguments[i]);
if(argType === 'function'){
if (argType === 'function') {
arguments[i].apply(null, args);

@@ -184,3 +196,4 @@ }

toThrow: toThrow,
toCallbackWith : toCallbackWith,
toCallbackWith: toCallbackWith,
toTimeWarp : toTimeWarp,
when: when,

@@ -187,0 +200,0 @@ call: call

{
"name": "deride",
"description": "Mocking library based on composition",
"version": "0.1.5",
"version": "0.1.6",
"homepage": "https://github.com/REAANDREW/deride",

@@ -6,0 +6,0 @@ "author": {

@@ -35,3 +35,4 @@ # deride [![Build Status](https://travis-ci.org/REAANDREW/deride.svg?branch=master)](https://travis-ci.org/REAANDREW/deride) [![NPM version](https://badge.fury.io/js/deride.svg)](http://badge.fury.io/js/deride) ![Dependencies Status](https://david-dm.org/reaandrew/deride.png)

- ```obj```.setup.```method```.toCallbackWith(args)
- ```obj```.setup.```method```.when(args).[toDoThis|toReturn|toThrow|toCallbackWith]
- ```obj```.setup.```method```.toTimeWarp(milliseconds)
- ```obj```.setup.```method```.when(args).[toDoThis|toReturn|toThrow|toCallbackWith|toTimeWarp]

@@ -116,3 +117,3 @@ ## Examples

### Override the invocation of a calback
### Override the invocation of a callback
```javascript

@@ -128,2 +129,22 @@ var bob = new Person('bob');

### Accelerating the timeout used internally by a function
```javascript
var Person = function(name) {
return Object.freeze({
foobar: function(timeout, callback) {
setTimeout(function() {
callback('result');
}, timeout);
}
});
};
var timeout = 10000;
var bob = new Person('bob');
bob = deride.wrap(bob);
bob.setup.foobar.toTimeWarp(timeout);
bob.foobar(timeout, function(message) {
assert.equal(message, 'result');
});
```
### Setting the return value of a function when specific arguments are used

@@ -172,3 +193,3 @@ ```javascript

### Override the invocation of a calback when specific arguments are provided
### Override the invocation of a callback when specific arguments are provided
```javascript

@@ -189,2 +210,29 @@ var bob = new Person('bob');

### Accelerating the timeout used internally by a function when specific arguments are provided
```javascript
var Person = function(name) {
return Object.freeze({
foobar: function(timeout, callback) {
setTimeout(function() {
callback('result');
}, timeout);
}
});
};
var timeout1 = 10000;
var timeout2 = 20000;
var bob = new Person('bob');
bob = deride.wrap(bob);
bob.setup.foobar.toTimeWarp(timeout1);
bob.setup.foobar.when(timeout2).toTimeWarp(timeout2);
bob.foobar(timeout1, function(message) {
assert.equal(message, 'result');
bob.foobar(timeout2, function(message) {
assert.equal(message, 'result');
done();
});
});
```
### Creating a stubbed object

@@ -214,2 +262,5 @@ Stubbing an object simply creates an anonymous object, with all the method specified and then the object is wrapped to provide all the expectation functionality of the library

- v0.1.6 - 25th April 2014
Added feature to support accelerating the timeout used internally by a function
## License

@@ -216,0 +267,0 @@ Copyright (c) 2014 Andrew Rea

@@ -49,6 +49,15 @@ /*

var fooBarFunction = function(timeout, callback) {
setTimeout(function() {
callback('result');
}, timeout);
};
var tests = [{
name: 'Creating a stub object',
setup: function() {
return deride.stub(['greet', 'chuckle']);
var stub = deride.stub(['greet', 'chuckle', 'foobar']);
stub.setup.foobar.toDoThis(fooBarFunction);
return stub;
}

@@ -62,3 +71,4 @@ }, {

},
chuckle: function() {}
chuckle: function() {},
foobar: fooBarFunction
};

@@ -76,3 +86,4 @@ return Person;

},
chuckle: function() {}
chuckle: function() {},
foobar: fooBarFunction
});

@@ -95,2 +106,3 @@ };

Person.prototype.chuckle = function() {};
Person.prototype.foobar = fooBarFunction;

@@ -173,2 +185,12 @@ return new Person('bob proto');

it('enables accelerating timeouts for functions', function(done) {
var timeout = 10000;
bob = deride.wrap(bob);
bob.setup.foobar.toTimeWarp(timeout);
bob.foobar(timeout, function(message) {
assert.equal(message, 'result');
done();
});
});
it('enables overriding a methods body when specific arguments are provided', function(done) {

@@ -238,3 +260,18 @@ bob = deride.wrap(bob);

});
it('enables accelerating timeouts for functions when specific arguments are provided', function(done) {
var timeout1 = 10000;
var timeout2 = 20000;
bob = deride.wrap(bob);
bob.setup.foobar.toTimeWarp(timeout1);
bob.setup.foobar.when(timeout2).toTimeWarp(timeout2);
bob.foobar(timeout1, function(message) {
assert.equal(message, 'result');
bob.foobar(timeout2, function(message) {
assert.equal(message, 'result');
done();
});
});
});
});
});
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