UNPKG

hamjest

Version:

A library of composable matchers for defining meaningful and readable assertions in JavaScript.

18 lines (15 loc) 601 B
'use strict'; const _ = require('lodash'); const TypeSafeMatcher = require('./TypeSafeMatcher'); const FeatureMatcher = require('./FeatureMatcher'); module.exports = function (valueOrMatcher) { const innerMatcher = new FeatureMatcher(valueOrMatcher, 'a collection or string with size', 'size', (item) => _.size(item)); return _.create(new TypeSafeMatcher(), { isExpectedType: function (actual) { return _.isString(actual) || _.isObject(actual); }, matchesSafely: innerMatcher.matches, describeTo: innerMatcher.describeTo, describeMismatchSafely: innerMatcher.describeMismatch }); };