Skip to content

Commit

Permalink
feat: contains allows for regexps against strings
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz committed Jan 17, 2017
1 parent f2c6091 commit f00a8d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/matchers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ module.exports =
_.isEqual(actualElement, containing)
else if _.isPlainObject(containing) && _.isPlainObject(actualArg)
containsAllSpecified(containing, actualArg)
else if _.isRegExp(containing)
containing.test(actualArg)
else
_.includes(actualArg, containing)

Expand Down
2 changes: 1 addition & 1 deletion src/util/lodash-wrap.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports =
isFunction: require('lodash/isFunction')
isNumber: require('lodash/isNumber')
isPlainObject: require('lodash/isPlainObject')
isRegExp: require('lodash/isRegExp')
isString: require('lodash/isString')
keys: require('lodash/keys')
last: require('lodash/last')
Expand All @@ -24,4 +25,3 @@ module.exports =
some: require('lodash/some')
tap: require('lodash/tap')
union: require('lodash/union')

8 changes: 5 additions & 3 deletions test/src/matchers-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ describe '.matchers', ->
Then -> @matches(td.matchers.contains(deep: {thing: 'stuff'}), deep: {thing: 'stuff', shallow: 5}) == true
Then -> @matches(td.matchers.contains({container: {size: 'S'}}), {ingredient: 'beans', container: { type: 'cup', size: 'S'}}) == true

context 'regexp', ->
Then -> @matches(td.matchers.contains(/abc/), 'abc') == true
Then -> @matches(td.matchers.contains(/abc/), foo: 'bar') == false
Then -> @matches(td.matchers.contains(/abc/), ['foo', 'bar']) == false

context 'nonsense', ->
Then -> @matches(td.matchers.contains(42), 42) == false
Then -> @matches(td.matchers.contains(null), 'shoo') == false
Expand All @@ -112,6 +117,3 @@ describe '.matchers', ->
Then -> @matches(td.matchers.not(5), 6) == true
Then -> @matches(td.matchers.not(5), 5) == false
Then -> @matches(td.matchers.not(['hi']), ['hi']) == false



0 comments on commit f00a8d1

Please sign in to comment.