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.1 to 0.1.3

23

lib/deride.js

@@ -29,4 +29,4 @@ /*

require('should');
var _ = require('lodash');
var assert = require('assert');

@@ -48,7 +48,6 @@ var methods = function(obj) {

var Expectations = function(obj, method) {
var Expectations = function() {
var timesCalled = 0;
var calledWithArgs = {};
var originalMethod = obj[method];

@@ -68,17 +67,23 @@ function withArgs() {

});
_.any(results).should.eql(true);
assert(_.any(results));
}
function times(number) {
timesCalled.should.eql(number);
assert.equal(timesCalled, number);
}
function never() {
timesCalled.should.eql(0);
assert.equal(timesCalled, 0);
}
function calledOnce() {
assert.equal(timesCalled, 1);
}
function calledTwice() {
assert.equal(timesCalled, 2);
}
function call() {
calledWithArgs[timesCalled++] = arguments;
var result = originalMethod.apply(obj, arguments);
return result;
}

@@ -90,2 +95,4 @@

never: never,
once : calledOnce,
twice: calledTwice,
withArgs: withArgs

@@ -92,0 +99,0 @@ },

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

@@ -11,7 +11,7 @@ "author": {

},
"contributors": [
"contributors": [
{
"name": "James Allen",
"url" : "https://github.com/jamlen"
}
"url": "https://github.com/jamlen"
}
],

@@ -46,3 +46,2 @@ "repository": {

"dependencies": {
"should": "~3.3.1",
"lodash": "~2.4.1"

@@ -49,0 +48,0 @@ },

@@ -24,2 +24,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```.expect.```method```.called.times(n)
- ```obj```.expect.```method```.called.once()
- ```obj```.expect.```method```.called.twice()
- ```obj```.expect.```method```.called.never()

@@ -56,2 +58,12 @@ - ```obj```.expect.```method```.called.withArgs(args)

### Has convenience methods for invocation counts
```javascript
var bob = new Person('bob');
bob = deride.wrap(bob);
bob.greet('alice');
bob.expect.greet.called.once();
bob.greet('sally');
bob.expect.greet.called.twice();
```
### Determine if a method has **never** been called

@@ -76,2 +88,3 @@ ```javascript

var bob = new Person('bob');
bob = deride.wrap(bob);
bob.setup.greet.toDoThis(function(otherPersonName) {

@@ -78,0 +91,0 @@ return util.format('yo %s', otherPersonName);

@@ -32,5 +32,19 @@ /*

var util = require('util');
var should = require('should');
var assert = require('assert');
describe('Excpectations', function(){
it('does not invoke original method when override method body', function(){
var obj = deride.stub(['send']);
obj.setup.send.toThrow('bang');
obj = deride.wrap(obj);
obj.setup.send.toDoThis(function(){
return 'hello';
});
var result = obj.send();
assert.equal(result,'hello');
});
});
var tests = [{

@@ -86,2 +100,17 @@ name: 'Creating a stub object',

it('enables convenience method for called.once', function(done){
bob = deride.wrap(bob);
bob.greet('alice');
bob.expect.greet.called.once();
done();
});
it('enables convenience method for called.twice', function(done){
bob = deride.wrap(bob);
bob.greet('alice');
bob.greet('sally');
bob.expect.greet.called.twice();
done();
});
it('enables the determination that a method has NEVER been called', function(done) {

@@ -107,3 +136,4 @@ bob = deride.wrap(bob);

var result = bob.greet('alice');
result.should.eql('yo alice');
//result.should.eql('yo alice');
assert.equal(result,'yo alice');
done();

@@ -116,3 +146,4 @@ });

var result = bob.greet('alice');
result.should.eql('foobar');
//result.should.eql('foobar');
assert.equal(result,'foobar');
done();

@@ -124,6 +155,5 @@ });

bob.setup.greet.toThrow('BANG');
should(function() {
assert.throws(function() {
bob.greet('alice');
}).
throw (/BANG/);
},/BANG/);
done();

@@ -142,4 +172,4 @@ });

var result2 = bob.greet('bob');
result1.should.eql('yo yo alice');
result2.should.eql('yo bob');
assert.equal(result1,'yo yo alice');
assert.equal(result2,'yo bob');
done();

@@ -154,4 +184,4 @@ });

var result2 = bob.greet('bob');
result1.should.eql('foobar');
result2.should.eql('barfoo');
assert.equal(result1,'foobar');
assert.equal(result2,'barfoo');
done();

@@ -164,10 +194,8 @@ });

bob.setup.greet.when('alice').toThrow('BANG');
should(function() {
assert.throws(function() {
bob.greet('alice');
}).
throw (/BANG/);
should(function() {
},/BANG/);
assert.doesNotThrow(function() {
bob.greet('bob');
}).not.
throw (/BANG/);
},/BANG/);
done();

@@ -174,0 +202,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