From d4168da1d6e732bdebebc90f2a0a7ae988edf63f Mon Sep 17 00:00:00 2001 From: Bruno Queiros Date: Wed, 9 Dec 2015 23:13:21 -0200 Subject: [PATCH 1/2] add contains assert --- lib/assert.js | 4 ++++ test/assert.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/assert.js b/lib/assert.js index 5bd84e981..9e766c6bb 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -120,4 +120,8 @@ x.ifError = x.error = function (err, msg) { test(!err, create(err, 'Error', '!==', msg, x.ifError)); }; +x.contains = function (val, expected, msg) { + test(val.indexOf(expected) > -1, create(val, expected, 'indexOf', msg, x.contains)); +}; + require('./enhance-assert')(x); diff --git a/test/assert.js b/test/assert.js index 83561005b..b6b391582 100644 --- a/test/assert.js +++ b/test/assert.js @@ -238,3 +238,19 @@ test('.same() should not mask RangeError from underlying assert', function (t) { t.end(); }); + +test('.contains()', function (t) { + t.doesNotThrow(function () { + assert.contains('Hello World!', 'Hello'); + }); + + t.doesNotThrow(function () { + assert.contains('Hello World!', 'lo Wor'); + }); + + t.throws(function () { + assert.contains('Hello World!', 'Planet'); + }); + + t.end(); +}); From 46935e38376b7de2abe92c8b597bb2d04f1884f3 Mon Sep 17 00:00:00 2001 From: Bruno Queiros Date: Wed, 9 Dec 2015 23:23:17 -0200 Subject: [PATCH 2/2] update readme.md with contains assert --- readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 37feaa467..79636b4a6 100644 --- a/readme.md +++ b/readme.md @@ -570,6 +570,10 @@ Assert that `regex` matches `contents`. Assert that `error` is falsy. +### .contains(value, expected, [message]) + +Assert that `value` contains `expected`. + ## Enhanced asserts @@ -695,4 +699,3 @@ Concurrency is not parallelism. It enables parallelism. [Learn more.](http://sta

-