From d1eafd084c0a5b2018a3bb033260e9653b7b02e5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 2 Dec 2017 10:31:51 +0100 Subject: [PATCH] Truthy test (#37) * Truthy test * Update dev --- package.json | 4 ++-- src/assert.js | 14 +++++++------- yarn.lock | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 069fa8e42..2b37f9225 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "test": "jest --coverage src" }, "devDependencies": { - "@polkadot/api-jsonrpc": "^0.5.5", - "@polkadot/dev": "^0.12.4" + "@polkadot/api-jsonrpc": "^0.5.9", + "@polkadot/dev": "^0.12.5" }, "dependencies": { "babel-runtime": "^6.26.0", diff --git a/src/assert.js b/src/assert.js index 6f8600646..98a119772 100644 --- a/src/assert.js +++ b/src/assert.js @@ -8,17 +8,17 @@ const ExtError = require('./ext/error'); @signature assert (test: boolean, message: string, code: number = ExtError.CODES.ASSERT, data: any): void @summary Checks for a valid test, if not ExtError is thrown. @description - Checks that `test` is a true value. If value is `false` (or `false-ish`), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned. + Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned. @example const assert = require('@polkadot/util/assert'); - assert(true === true, 'True should be true'); // true returned - assert(false === true, 'False should not be true'); // ExtError thrown + assert(true, 'True should be true'); // true returned + assert(false, 'False should not be true'); // ExtError thrown */ -module.exports = function assert (test: boolean, message: string, code: number = ExtError.CODES.ASSERT, data: any): boolean { - if (!test) { - throw new ExtError(message, code, data); +module.exports = function assert (test: any, message: string, code: number = ExtError.CODES.ASSERT, data: any): boolean { + if (test) { + return true; } - return true; + throw new ExtError(message, code, data); }; diff --git a/yarn.lock b/yarn.lock index 9512bc183..db3d502e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -54,15 +54,15 @@ lodash "^4.2.0" to-fast-properties "^2.0.0" -"@polkadot/api-jsonrpc@^0.5.5": - version "0.5.5" - resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.5.5.tgz#004ed19c2c5585230c8ec77caee78b5f6d61e62a" +"@polkadot/api-jsonrpc@^0.5.9": + version "0.5.9" + resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.5.9.tgz#615311c4f7c73b95cb52e910250ecc712f695732" dependencies: babel-runtime "^6.26.0" -"@polkadot/dev@^0.12.4": - version "0.12.4" - resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.12.4.tgz#5ce16c17bc29cf92793900a4096c7cc76cf2a0ac" +"@polkadot/dev@^0.12.5": + version "0.12.5" + resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.12.5.tgz#695238baf1f7fb6368b2191ca7bfa432d3e779ae" dependencies: babel-cli "^6.26.0" babel-core "^6.26.0"