Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jasmine-matchers

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jasmine-matchers - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

2

package.json

@@ -6,3 +6,3 @@ {

"private": false,
"version": "0.2.0",
"version": "0.2.1",
"homepage": "https://github.com/uxebu/jasmine-matchers/",

@@ -9,0 +9,0 @@ "main": "src/matchers.js",

@@ -1,38 +0,76 @@

beforeEach(function() {
this.addMatchers({
(function() {
function testKeyList(keys, object, testFn) {
for (var i = 0, len = keys.length; i < len; i += 1) {
if (!testFn(object, keys[i])) {
return false;
}
}
return true;
}
toHaveBeenCalledXTimes: function(count) {
var callCount = this.actual.callCount;
var not = this.isNot ? "NOT " : "";
this.message = function() {
return 'Expected spy "' + this.actual.identity + '" ' + not + ' to have been called ' + count + ' times, but was ' + callCount + '.';
};
return callCount == count;
},
function testKeyObject(referenceObject, object, testFn) {
for (var key in referenceObject) {
if (!testFn(object, key, referenceObject[key])) {
return false;
}
}
return true;
}
toHaveLength: function(length) {
return this.actual.length === length;
},
function hasProperty(object, key) {
return key in object;
}
function hasOwnProperty(object, key) {
return {}.hasOwnProperty.call(object, key);
}
function hasPropertyWithValue(object, key, value) {
return object[key] === value;
}
function hasOwnPropertyWithValue(object, key, value) {
return hasOwnProperty(object, key) && hasPropertyWithValue(object, key, value);
}
toHaveOwnProperties: function(name0, name1, name2) {
var actual = this.actual, hasOwnProperty = {}.hasOwnProperty;
for (var i = 0, len = arguments.length; i < len; i += 1) {
if (!hasOwnProperty.call(actual, arguments[i])) {
return false;
}
}
return true;
},
beforeEach(function() {
this.addMatchers({
toHaveProperties: function(name0, name1, name2) {
var actual = this.actual;
for (var i = 0, len = arguments.length; i < len; i += 1) {
if (!(arguments[i] in actual)) {
return false;
toHaveBeenCalledXTimes: function(count) {
var callCount = this.actual.callCount;
var not = this.isNot ? "NOT " : "";
this.message = function() {
return 'Expected spy "' + this.actual.identity + '" ' + not + ' to have been called ' + count + ' times, but was ' + callCount + '.';
};
return callCount == count;
},
toHaveLength: function(length) {
return this.actual.length === length;
},
toHaveOwnProperties: function(name0, name1, name2) {
return testKeyList(arguments, this.actual, hasOwnProperty);
},
toHaveOwnPropertiesWithValues: function(obj) {
return testKeyObject(obj, this.actual, hasOwnPropertyWithValue);
},
toHaveProperties: function(name0, name1, name2) {
return testKeyList(arguments, this.actual, hasProperty);
},
toHavePropertiesWithValues: function(obj) {
return testKeyObject(obj, this.actual, hasPropertyWithValue);
},
toExactlyHaveProperties: function(name0, name1, name2) {
var actual = this.actual;
var numArguments = arguments.length;
for (var i = 0; i < numArguments; i += 1) {
if (!hasOwnProperty(actual, arguments[i])) { return false; }
}
return Object.keys(actual).length === numArguments;
}
return true;
}
});
});
});
}());

@@ -7,3 +7,3 @@ require([], function() {

it('should work for `{length:null}`', function() {
expect({length:null}).toHaveLength(null);
expect({length: null}).toHaveLength(null);
});

@@ -18,7 +18,24 @@ });

it('should work for `{x:0, y:undefined}`', function() {
var obj = {x:0, y:undefined};
var obj = {x: 0, y: undefined};
expect(obj).toHaveProperties('x', 'y');
});
});
});
describe('toHavePropertiesWithValues', function() {
describe('matches', function() {
it('should work with a reference object', function() {
function C() { this.x = 0; }
C.prototype.y = 'arbitrary';
expect(new C).toHavePropertiesWithValues({
x: 0,
y: 'arbitrary',
constructor: C
});
});
});
});

@@ -30,7 +47,22 @@

it('should work for `{x:0, y:undefined}`', function() {
var obj = {x:0, y:undefined};
var obj = {x: 0, y: undefined};
expect(obj).toHaveOwnProperties('x', 'y');
});
});
});
describe('toHaveOwnPropertiesWithValues', function() {
describe('matches', function() {
it('should work with a reference object', function() {
expect({
x: 0,
y: 'arbitrary'
}).toHaveOwnPropertiesWithValues({
x: 0,
y: 'arbitrary'
});
});
});
});

@@ -57,2 +89,32 @@

describe('toExactlyHaveProperties', function() {
describe('matches', function() {
it('should work for `{x:0, y:undefined}`', function() {
var obj = {x: 0, y: undefined};
expect(obj)
.toExactlyHaveProperties('x', 'y');
});
it('should work in any order', function() {
var obj = {x: 0, y: undefined};
expect(obj)
.toExactlyHaveProperties('y', 'x');
});
});
describe('non-matches', function() {
it('should work for too many properties', function() {
var obj = {x: 0, y: undefined};
expect(obj)
.not.toExactlyHaveProperties('x');
});
it('should work for missing properties', function() {
var obj = {x: 0, y: undefined};
expect(obj)
.not.toExactlyHaveProperties('x', 'y', 'z');
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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