Socket
Socket
Sign inDemoInstall

truffle-expect

Package Overview
Dependencies
Maintainers
7
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

truffle-expect - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

test/index.js

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
```
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