jasmine-matchers
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
55640
786
0