truffle-expect
Advanced tools
Comparing version 0.0.7 to 0.0.8
28
index.js
@@ -1,6 +0,6 @@ | ||
var Expect = { | ||
options: function(options, expected_keys) { | ||
expected_keys.forEach(function(key) { | ||
const Expect = { | ||
options(options, expected_keys) { | ||
expected_keys.forEach(key => { | ||
if (options[key] == null) { | ||
throw new Error("Expected parameter '" + key + "' not passed to function."); | ||
throw new Error(`Expected parameter '${key}' not passed to function.`); | ||
} | ||
@@ -10,6 +10,6 @@ }); | ||
one: function(options, expected_keys) { | ||
var found = []; | ||
one(options, expected_keys) { | ||
const found = []; | ||
expected_keys.forEach(function(key) { | ||
expected_keys.forEach(key => { | ||
if (options[key] != null) { | ||
@@ -22,11 +22,13 @@ found.push(1); | ||
var total = found.reduce(function(t, value) { | ||
return t + value; | ||
}); | ||
const total = found.reduce((t, value) => t + value); | ||
// If this doesn't work in all cases, perhaps we should | ||
// create an expect.onlyOne() function. | ||
if (total >= 1) return; | ||
throw new Error("Expected one of the following parameters, but found none: " + expected_keys.join(", ")); | ||
if (total < 1) { | ||
throw new Error( | ||
`Expected one of the following parameters, but found none: ${expected_keys.join( | ||
", " | ||
)}` | ||
); | ||
} | ||
} | ||
@@ -33,0 +35,0 @@ }; |
{ | ||
"name": "truffle-expect", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Simple module for ensuring specific options are passed to a function", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": "https://github.com/trufflesuite/truffle/tree/master/packages/truffle-expect", | ||
@@ -16,9 +18,12 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/trufflesuite/truffle-expect/issues" | ||
"url": "https://github.com/trufflesuite/truffle/issues" | ||
}, | ||
"homepage": "https://github.com/trufflesuite/truffle-expect#readme", | ||
"homepage": "https://github.com/trufflesuite/truffle/blob/master/packages/truffle-expect#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "7059e6a06de0c4fb5c4a40a09ef206c3e3c357fe" | ||
"gitHead": "e0c7c9f7c36cc42cd84a92a48e41fe125a5bd274", | ||
"devDependencies": { | ||
"mocha": "5.2.0" | ||
} | ||
} |
@@ -13,12 +13,15 @@ # truffle-expect | ||
```javascript | ||
var expect = require("truffle-expect"); | ||
const expect = require("truffle-expect"); | ||
// The object you're testing | ||
var options = { | ||
example: "exists" | ||
// the object you're testing | ||
const options = { | ||
example: "exists", | ||
another: 5 | ||
}; | ||
expect.options(options, ["example", "another"]); // does nothing | ||
expect.options(options, ["example", "another"]); // does nothing because both key values exist | ||
expect.options(options, ["example", "another", "some_other_key"]); // errors because options["some_other_key"] is undefined | ||
expect.one(options, ["example", "optional_key"]); // does nothing because at least one key value exists | ||
expect.one(options, ["optional_key", "other_optional_key"]); // errors because both key values are undefined | ||
``` |
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
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
No website
QualityPackage does not have a website.
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
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
2661
4
45
27
1
2