hamjest 3.7.3 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.eslintrc +15 -11
  2. package/dist/hamjest.js +6542 -23401
  3. package/dist/hamjest.min.js +1 -1
  4. package/gulpfile.js +0 -2
  5. package/index.js +95 -1
  6. package/lib/Description.js +32 -22
  7. package/lib/assertThat.js +4 -4
  8. package/lib/matchers/AllOf.js +8 -5
  9. package/lib/matchers/AnyOf.js +8 -8
  10. package/lib/matchers/DateComparisonMatcher.js +25 -24
  11. package/lib/matchers/Every.js +17 -11
  12. package/lib/matchers/FeatureMatcher.js +2 -2
  13. package/lib/matchers/Is.js +6 -5
  14. package/lib/matchers/IsAnything.js +2 -2
  15. package/lib/matchers/IsArray.js +4 -3
  16. package/lib/matchers/IsArrayContaining.js +8 -6
  17. package/lib/matchers/IsArrayContainingInAnyOrder.js +11 -8
  18. package/lib/matchers/IsArrayOrderedBy.js +5 -4
  19. package/lib/matchers/IsArrayWithItem.js +11 -8
  20. package/lib/matchers/IsArrayWithItems.js +6 -4
  21. package/lib/matchers/IsBoolean.js +4 -3
  22. package/lib/matchers/IsCloseTo.js +2 -2
  23. package/lib/matchers/IsDate.js +4 -3
  24. package/lib/matchers/IsDefined.js +4 -3
  25. package/lib/matchers/IsEqual.js +4 -3
  26. package/lib/matchers/IsFulfilled.js +2 -2
  27. package/lib/matchers/IsFunction.js +4 -3
  28. package/lib/matchers/IsFunctionThrowing.js +2 -2
  29. package/lib/matchers/IsInstanceOf.js +4 -3
  30. package/lib/matchers/IsNot.js +6 -5
  31. package/lib/matchers/IsNumber.js +4 -3
  32. package/lib/matchers/IsObject.js +4 -3
  33. package/lib/matchers/IsObjectWithProperties.js +19 -12
  34. package/lib/matchers/IsPromise.js +4 -3
  35. package/lib/matchers/IsRegExp.js +5 -6
  36. package/lib/matchers/IsRejected.js +2 -2
  37. package/lib/matchers/IsSame.js +2 -2
  38. package/lib/matchers/IsString.js +4 -3
  39. package/lib/matchers/IsStringMatching.js +2 -2
  40. package/lib/matchers/Matcher.js +10 -7
  41. package/lib/matchers/NumberComparisonMatcher.js +17 -16
  42. package/lib/matchers/SubstringMatcher.js +42 -39
  43. package/lib/matchers/failsToMatch.js +2 -2
  44. package/lib/matchers/falsy.js +2 -2
  45. package/lib/matchers/hasDescription.js +6 -5
  46. package/lib/matchers/hasExactlyOneItem.js +11 -8
  47. package/lib/matchers/hasSize.js +7 -4
  48. package/lib/matchers/inRange.js +11 -8
  49. package/lib/matchers/isEmpty.js +2 -2
  50. package/lib/matchers/matches.js +2 -2
  51. package/lib/matchers/promiseAgnostic.js +35 -15
  52. package/lib/matchers/returns.js +2 -2
  53. package/lib/matchers/truthy.js +2 -2
  54. package/lib/promiseThat.js +7 -9
  55. package/package.json +4 -5
  56. package/test/node/assertThatSpec.js +1 -3
  57. package/test/node/deferMatcher.js +2 -4
  58. package/test/node/esm/.eslintrc +5 -0
  59. package/test/node/esm/package.json +3 -0
  60. package/test/node/esm/providesNamedImports.js +3 -0
  61. package/test/node/matchers/AllOfSpec.js +1 -1
  62. package/test/node/matchers/AnyOfSpec.js +1 -1
  63. package/test/node/matchers/IsFulfilledSpec.js +29 -30
  64. package/test/node/matchers/IsPromiseSpec.js +3 -4
  65. package/test/node/matchers/IsRejectedSpec.js +21 -22
  66. package/test/node/promiseThatSpec.js +49 -86
  67. package/lib/hamjest.js +0 -106
  68. package/tags +0 -2855
package/gulpfile.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- process.env.BLUEBIRD_DEBUG = 1;
4
-
5
3
  const gulp = require('gulp');
6
4
  const gulpEslint = require('gulp-eslint');
7
5
  const gulpMocha = require('gulp-mocha');
package/index.js CHANGED
@@ -1,3 +1,97 @@
1
1
  'use strict';
2
2
 
3
- module.exports = require('./lib/hamjest');
3
+ const IsEqual = require('./lib/matchers/IsEqual');
4
+ const Matcher = require('./lib/matchers/Matcher');
5
+ const SubstringMatcher = require('./lib/matchers/SubstringMatcher');
6
+ const NumberComparisonMatcher = require('./lib/matchers/NumberComparisonMatcher');
7
+ const DateComparisonMatcher = require('./lib/matchers/DateComparisonMatcher');
8
+ const Description = require('./lib/Description');
9
+
10
+ require('./lib/fixErrorJson')();
11
+
12
+ // asserts
13
+ module.exports.assertThat = require('./lib/assertThat');
14
+ module.exports.promiseThat = require('./lib/promiseThat');
15
+ module.exports.fail = require('./lib/fail');
16
+
17
+ // matchers
18
+ module.exports.Matcher = Matcher;
19
+ module.exports.TypeSafeMatcher = require('./lib/matchers/TypeSafeMatcher');
20
+ module.exports.FeatureMatcher = require('./lib/matchers/FeatureMatcher');
21
+
22
+ module.exports.anything = require('./lib/matchers/IsAnything').anything;
23
+ module.exports.strictlyEqualTo = require('./lib/matchers/IsSame').strictlyEqualTo;
24
+ module.exports.is = require('./lib/matchers/Is').is;
25
+ module.exports.not = require('./lib/matchers/IsNot').not;
26
+ module.exports.equalTo = IsEqual.equalTo;
27
+ module.exports.truthy = require('./lib/matchers/truthy');
28
+ module.exports.falsy = require('./lib/matchers/falsy');
29
+ module.exports.falsey = require('./lib/matchers/falsy');
30
+ module.exports.defined = require('./lib/matchers/IsDefined').defined;
31
+ module.exports.undefined = require('./lib/matchers/IsDefined').undefined;
32
+ module.exports.undef = require('./lib/matchers/IsDefined').undefined;
33
+ module.exports.instanceOf = require('./lib/matchers/IsInstanceOf').instanceOf;
34
+ module.exports.array = require('./lib/matchers/IsArray').array;
35
+ module.exports.bool = require('./lib/matchers/IsBoolean').bool;
36
+ module.exports.boolean = require('./lib/matchers/IsBoolean').bool;
37
+ module.exports.date = require('./lib/matchers/IsDate').date;
38
+ module.exports.func = require('./lib/matchers/IsFunction').func;
39
+ module.exports.number = require('./lib/matchers/IsNumber').number;
40
+ module.exports.object = require('./lib/matchers/IsObject').object;
41
+ module.exports.regExp = require('./lib/matchers/IsRegExp').regExp;
42
+ module.exports.string = require('./lib/matchers/IsString').string;
43
+ module.exports.containsString = SubstringMatcher.containsString;
44
+ module.exports.containsStrings = SubstringMatcher.containsStrings;
45
+ module.exports.startsWith = SubstringMatcher.startsWith;
46
+ module.exports.endsWith = SubstringMatcher.endsWith;
47
+ module.exports.matchesPattern = require('./lib/matchers/IsStringMatching').matchesPattern;
48
+ module.exports.matches = require('./lib/matchers/matches');
49
+ module.exports.failsToMatch = require('./lib/matchers/failsToMatch');
50
+ module.exports.hasDescription = require('./lib/matchers/hasDescription');
51
+ module.exports.lessThan = NumberComparisonMatcher.lessThan;
52
+ module.exports.lessThanOrEqualTo = NumberComparisonMatcher.lessThanOrEqualTo;
53
+ module.exports.greaterThan = NumberComparisonMatcher.greaterThan;
54
+ module.exports.greaterThanOrEqualTo = NumberComparisonMatcher.greaterThanOrEqualTo;
55
+ module.exports.inRange = require('./lib/matchers/inRange');
56
+ module.exports.after = DateComparisonMatcher.after;
57
+ module.exports.afterOrEqualTo = DateComparisonMatcher.afterOrEqualTo;
58
+ module.exports.before = DateComparisonMatcher.before;
59
+ module.exports.beforeOrEqualTo = DateComparisonMatcher.beforeOrEqualTo;
60
+ module.exports.closeTo = require('./lib/matchers/IsCloseTo').closeTo;
61
+ module.exports.allOf = require('./lib/matchers/AllOf').allOf;
62
+ module.exports.anyOf = require('./lib/matchers/AnyOf').anyOf;
63
+ module.exports.everyItem = require('./lib/matchers/Every').everyItem;
64
+ module.exports.hasItem = require('./lib/matchers/IsArrayWithItem').hasItem;
65
+ module.exports.hasItems = require('./lib/matchers/IsArrayWithItems').hasItems;
66
+ module.exports.hasExactlyOneItem = require('./lib/matchers/hasExactlyOneItem');
67
+ module.exports.contains = require('./lib/matchers/IsArrayContaining').contains;
68
+ module.exports.containsInAnyOrder = require('./lib/matchers/IsArrayContainingInAnyOrder').containsInAnyOrder;
69
+ module.exports.orderedBy = require('./lib/matchers/IsArrayOrderedBy').orderedBy;
70
+ module.exports.hasSize = require('./lib/matchers/hasSize');
71
+ module.exports.isEmpty = require('./lib/matchers/isEmpty');
72
+ module.exports.empty = require('./lib/matchers/isEmpty');
73
+ module.exports.hasProperties = require('./lib/matchers/IsObjectWithProperties').hasProperties;
74
+ module.exports.hasDeepProperties = require('./lib/matchers/IsObjectWithProperties').hasDeepProperties;
75
+ module.exports.hasProperty = require('./lib/matchers/IsObjectWithProperties').hasProperty;
76
+ module.exports.throws = require('./lib/matchers/IsFunctionThrowing').throws;
77
+ module.exports.returns = require('./lib/matchers/returns');
78
+ module.exports.typedError = require('./lib/matchers/typedError');
79
+ module.exports.promise = require('./lib/matchers/IsPromise').promise;
80
+ module.exports.fulfilled = require('./lib/matchers/IsFulfilled').fulfilled;
81
+ module.exports.isFulfilledWith = require('./lib/matchers/IsFulfilled').isFulfilledWith;
82
+ module.exports.willBe = require('./lib/matchers/IsFulfilled').isFulfilledWith;
83
+ module.exports.rejected = require('./lib/matchers/IsRejected').rejected;
84
+ module.exports.isRejectedWith = require('./lib/matchers/IsRejected').isRejectedWith;
85
+ // Deprecated
86
+ module.exports.promiseAllOf = require('./lib/matchers/AllOf').allOf;
87
+
88
+ // utils
89
+ module.exports.isMatcher = Matcher.isMatcher;
90
+ module.exports.asMatcher = require('./lib/utils/asMatcher');
91
+ module.exports.acceptingMatcher = require('./lib/utils/acceptingMatcher');
92
+ module.exports.Description = Description;
93
+ module.exports.describe = function (matcher) {
94
+ return new Description()
95
+ .appendDescriptionOf(matcher)
96
+ .get();
97
+ };
@@ -1,10 +1,17 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
4
- const Bluebird = require('bluebird');
3
+ const _forEach = require('lodash/forEach');
4
+ const _isArray = require('lodash/isArray');
5
+ const _isFunction = require('lodash/isFunction');
6
+ const _isNull = require('lodash/isNull');
7
+ const _isNumber = require('lodash/isNumber');
8
+ const _isRegExp = require('lodash/isRegExp');
9
+ const _isString = require('lodash/isString');
10
+ const _isUndefined = require('lodash/isUndefined');
11
+ const _padEnd = require('lodash/padEnd');
5
12
 
6
13
  function asSelfDescribing(value) {
7
- if (!value || !_.isFunction(value.describeTo)) {
14
+ if (!value || !_isFunction(value.describeTo)) {
8
15
  return {
9
16
  describeTo(description) {
10
17
  description.appendValue(value);
@@ -26,7 +33,7 @@ function Description() {
26
33
  indentation: 0,
27
34
  append(text) {
28
35
  if (this.indentation) {
29
- text = ('' + text).replace('\n', _.padEnd('\n', this.indentation + 1, '\t'));
36
+ text = ('' + text).replace('\n', _padEnd('\n', this.indentation + 1, '\t'));
30
37
  }
31
38
  try {
32
39
  value += text;
@@ -38,18 +45,21 @@ function Description() {
38
45
  indented(describingfn) {
39
46
  this.indentation += 1;
40
47
  const result = describingfn();
41
- if (result && _.isFunction(result.then)) {
42
- return Bluebird.resolve(result)
43
- .finally(() => {
44
- this.indentation -= 1;
45
- });
48
+ if (result && _isFunction(result.then)) {
49
+ const decrementIndentation = () => { this.indentation -= 1; };
50
+ // Promise.finally based on https://www.npmjs.com/package/finally-polyfill
51
+ return Promise.resolve(result)
52
+ .then(
53
+ (result) => Promise.resolve(decrementIndentation()).then(result),
54
+ (error) => Promise.resolve(decrementIndentation()).then(() => { throw error; })
55
+ );
46
56
  } else {
47
57
  this.indentation -= 1;
48
58
  return result;
49
59
  }
50
60
  },
51
61
  appendDescriptionOf(selfDescribing) {
52
- if (selfDescribing && _.isFunction(selfDescribing.describeTo)) {
62
+ if (selfDescribing && _isFunction(selfDescribing.describeTo)) {
53
63
  selfDescribing.describeTo(this);
54
64
  } else {
55
65
  this.appendValue(selfDescribing);
@@ -57,19 +67,19 @@ function Description() {
57
67
  return this;
58
68
  },
59
69
  appendValue(value, indentLists) {
60
- if (_.isUndefined(value)) {
70
+ if (_isUndefined(value)) {
61
71
  this.append('undefined');
62
- } else if (_.isNull(value)) {
72
+ } else if (_isNull(value)) {
63
73
  this.append('null');
64
- } else if (_.isString(value)) {
74
+ } else if (_isString(value)) {
65
75
  this.append('"');
66
76
  this.append(value);
67
77
  this.append('"');
68
- } else if (_.isNumber(value)) {
78
+ } else if (_isNumber(value)) {
69
79
  this.append('<');
70
80
  this.append(value);
71
81
  this.append('>');
72
- } else if (_.isArray(value)) {
82
+ } else if (_isArray(value)) {
73
83
  if (indentLists && value.length > 1) {
74
84
  this.indented(() => this.appendList('[\n', ',\n', '', value))
75
85
  .append('\n]');
@@ -78,10 +88,10 @@ function Description() {
78
88
  }
79
89
  } else if (isDomNode(value)) {
80
90
  this.append('DOM node ')
81
- .appendValue(_.isFunction(value.html) ? value.html() : value.outerHTML);
82
- } else if (_.isFunction(value)) {
91
+ .appendValue(_isFunction(value.html) ? value.html() : value.outerHTML);
92
+ } else if (_isFunction(value)) {
83
93
  this.append('Function' + (value.name ? ' ' + value.name : ''));
84
- } else if (_.isRegExp(value)) {
94
+ } else if (_isRegExp(value)) {
85
95
  this.append(value.toString());
86
96
  } else if (this.useJsonForObjects) {
87
97
  try {
@@ -100,7 +110,7 @@ function Description() {
100
110
  appendNonJson(value) {
101
111
  this.append('{');
102
112
  let first = true;
103
- _.forEach(value, (innerValue, key) => {
113
+ _forEach(value, (innerValue, key) => {
104
114
  if (!first) {
105
115
  this.append(', ');
106
116
  }
@@ -113,7 +123,7 @@ function Description() {
113
123
  },
114
124
  appendList(start, separator, end, list) {
115
125
  this.append(start);
116
- _.forEach(list, (value, index) => {
126
+ _forEach(list, (value, index) => {
117
127
  if (index !== 0) {
118
128
  this.append(separator);
119
129
  }
@@ -131,8 +141,8 @@ function Description() {
131
141
  if (!value) {
132
142
  return false;
133
143
  }
134
- return _.isFunction(value.appendChild) && _.isFunction(value.isEqualNode) && !_.isUndefined(value.outerHTML) ||
135
- _.isFunction(value.html) && _.isFunction(value.text);
144
+ return _isFunction(value.appendChild) && _isFunction(value.isEqualNode) && !_isUndefined(value.outerHTML) ||
145
+ _isFunction(value.html) && _isFunction(value.text);
136
146
  }
137
147
  }
138
148
 
package/lib/assertThat.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _isFunction = require('lodash/isFunction');
4
4
  const AssertionError = require('assertion-error');
5
5
  const Description = require('./Description');
6
6
  const asMatcher = require('./utils/asMatcher');
@@ -15,7 +15,7 @@ const assertThat = (...args) => {
15
15
  const {reason, matcher, actual} = processArgs(args);
16
16
  const matches = matcher.matches(actual);
17
17
 
18
- if (matches && _.isFunction(matches.then)) {
18
+ if (matches && _isFunction(matches.then)) {
19
19
  throw new AssertionError('Matcher returned a promise instead of a boolean - use promiseThat for promising matchers!', {}, assertThat);
20
20
  }
21
21
 
@@ -28,8 +28,8 @@ const assertThat = (...args) => {
28
28
  matcher.describeMismatch(actual, description);
29
29
 
30
30
  let errorProperties = {};
31
- if (_.isFunction(matcher.getExpectedForDiff) &&
32
- _.isFunction(matcher.formatActualForDiff)) {
31
+ if (_isFunction(matcher.getExpectedForDiff) &&
32
+ _isFunction(matcher.formatActualForDiff)) {
33
33
  errorProperties = {
34
34
  showDiff: true,
35
35
  expected: matcher.getExpectedForDiff(),
@@ -1,23 +1,26 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
+ const _every = require('lodash/every');
5
+ const _map = require('lodash/map');
6
+ const _mapValues = require('lodash/mapValues');
4
7
  const Matcher = require('./Matcher');
5
8
  const promiseAgnostic = require('./promiseAgnostic');
6
9
 
7
10
  function AllOf(matchers) {
8
- return _.create(new Matcher(), {
11
+ return _create(new Matcher(), {
9
12
  matches: function (actual) {
10
- const results = _.map(matchers, (matcher) => {
13
+ const results = _map(matchers, (matcher) => {
11
14
  return matcher.matches(actual);
12
15
  });
13
16
 
14
- return promiseAgnostic.matchesAggregate(results, _.every);
17
+ return promiseAgnostic.matchesAggregate(results, _every);
15
18
  },
16
19
  describeTo: function (description) {
17
20
  description.appendList('(', ' and ', ')', matchers);
18
21
  },
19
22
  describeMismatch: function (actual, description) {
20
- const results = _.mapValues(matchers, (matcher) => {
23
+ const results = _mapValues(matchers, (matcher) => {
21
24
  return matcher.matches(actual);
22
25
  });
23
26
  let first = true;
@@ -1,20 +1,20 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
+ const _map = require('lodash/map');
5
+ const _some = require('lodash/some');
4
6
  const Matcher = require('./Matcher');
5
-
6
7
  const promiseAgnostic = require('./promiseAgnostic');
8
+ const asMatcher = require('../utils/asMatcher');
7
9
 
8
10
  function AnyOf(matchers) {
9
- const __ = require('../..');
10
-
11
- return _.create(new Matcher(), {
11
+ return _create(new Matcher(), {
12
12
  matches: function (actual) {
13
- const results = _.map(matchers, (matcher) => {
14
- return __.asMatcher(matcher).matches(actual);
13
+ const results = _map(matchers, (matcher) => {
14
+ return asMatcher(matcher).matches(actual);
15
15
  });
16
16
 
17
- return promiseAgnostic.matchesAggregate(results, _.some);
17
+ return promiseAgnostic.matchesAggregate(results, _some);
18
18
  },
19
19
  describeTo: function (description) {
20
20
  description.appendList('(', ' or ', ')', matchers);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
4
  const IsDate = require('./IsDate');
5
5
  const assertThat = require('../assertThat');
6
6
  const is = require('./Is').is;
@@ -9,7 +9,7 @@ const date = require('./IsDate').date;
9
9
  function DateComparisonMatcher(threshold, relation, matchesNumber) {
10
10
  assertThat(threshold, is(date()));
11
11
 
12
- return _.create(new IsDate(), {
12
+ return _create(new IsDate(), {
13
13
  matchesSafely: function (actual) {
14
14
  return matchesNumber.call(this, actual);
15
15
  },
@@ -28,27 +28,28 @@ function DateComparisonMatcher(threshold, relation, matchesNumber) {
28
28
  });
29
29
  }
30
30
 
31
- _.extend(DateComparisonMatcher, {
32
- after: function (threshold) {
33
- return new DateComparisonMatcher(threshold, 'after', (actual) => {
34
- return actual > threshold;
35
- });
36
- },
37
- afterOrEqualTo: function (threshold) {
38
- return new DateComparisonMatcher(threshold, 'after or equal to', (actual) => {
39
- return actual >= threshold;
40
- });
41
- },
42
- before: function (threshold) {
43
- return new DateComparisonMatcher(threshold, 'before', (actual) => {
44
- return actual < threshold;
45
- });
46
- },
47
- beforeOrEqualTo: function (threshold) {
48
- return new DateComparisonMatcher(threshold, 'before or equal to', (actual) => {
49
- return actual <= threshold;
50
- });
51
- }
52
- });
31
+ DateComparisonMatcher.after = function (threshold) {
32
+ return new DateComparisonMatcher(threshold, 'after', (actual) => {
33
+ return actual > threshold;
34
+ });
35
+ };
36
+
37
+ DateComparisonMatcher.afterOrEqualTo = function (threshold) {
38
+ return new DateComparisonMatcher(threshold, 'after or equal to', (actual) => {
39
+ return actual >= threshold;
40
+ });
41
+ };
42
+
43
+ DateComparisonMatcher.before = function (threshold) {
44
+ return new DateComparisonMatcher(threshold, 'before', (actual) => {
45
+ return actual < threshold;
46
+ });
47
+ };
48
+
49
+ DateComparisonMatcher.beforeOrEqualTo = function (threshold) {
50
+ return new DateComparisonMatcher(threshold, 'before or equal to', (actual) => {
51
+ return actual <= threshold;
52
+ });
53
+ };
53
54
 
54
55
  module.exports = DateComparisonMatcher;
@@ -1,21 +1,27 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
+ const _every = require('lodash/every');
5
+ const _isArray = require('lodash/isArray');
6
+ const _isObject = require('lodash/isObject');
7
+ const _map = require('lodash/map');
8
+ const _mapValues = require('lodash/mapValues');
4
9
  const TypeSafeMatcher = require('./TypeSafeMatcher');
5
- const acceptingMatcher = require('../utils/acceptingMatcher');
6
10
  const promiseAgnostic = require('./promiseAgnostic');
11
+ const asMatcher = require('../utils/asMatcher');
7
12
 
8
- const Every = acceptingMatcher((matcher) => {
9
- return _.create(new TypeSafeMatcher(), {
13
+ function Every(valueOrMatcher) {
14
+ const matcher = asMatcher(valueOrMatcher);
15
+ return _create(new TypeSafeMatcher(), {
10
16
  isExpectedType: function (actual) {
11
- return _.isArray(actual) || _.isObject(actual);
17
+ return _isArray(actual) || _isObject(actual);
12
18
  },
13
19
  matchesSafely: function (actual) {
14
- const results = _.map(actual, (value) => {
20
+ const results = _map(actual, (value) => {
15
21
  return matcher.matches(value);
16
22
  });
17
23
 
18
- return promiseAgnostic.matchesAggregate(results, _.every);
24
+ return promiseAgnostic.matchesAggregate(results, _every);
19
25
  },
20
26
  describeTo: function (description) {
21
27
  description
@@ -24,12 +30,12 @@ const Every = acceptingMatcher((matcher) => {
24
30
  },
25
31
  describeMismatchSafely: function (actual, description) {
26
32
  let results;
27
- if (_.isArray(actual)) {
28
- results = _.map(actual, (value) => {
33
+ if (_isArray(actual)) {
34
+ results = _map(actual, (value) => {
29
35
  return matcher.matches(value);
30
36
  });
31
37
  } else {
32
- results = _.mapValues(actual, (value) => {
38
+ results = _mapValues(actual, (value) => {
33
39
  return matcher.matches(value);
34
40
  });
35
41
  }
@@ -44,7 +50,7 @@ const Every = acceptingMatcher((matcher) => {
44
50
  });
45
51
  }
46
52
  });
47
- });
53
+ }
48
54
 
49
55
  Every.everyItem = function (valueOrMatcher) {
50
56
  return new Every(valueOrMatcher);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
4
  const Matcher = require('./Matcher');
5
5
  const asMatcher = require('../utils/asMatcher');
6
6
  const promiseAgnostic = require('./promiseAgnostic');
@@ -11,7 +11,7 @@ function FeatureMatcher(valueOrMatcher, featureDescription, featureName, feature
11
11
  return item[featureName];
12
12
  };
13
13
 
14
- return _.create(new Matcher(), {
14
+ return _create(new Matcher(), {
15
15
  matches: function (actual) {
16
16
  const featureValue = featureFunction(actual);
17
17
  return matcher.matches(featureValue);
@@ -1,11 +1,12 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
4
  const Matcher = require('./Matcher');
5
- const acceptingMatcher = require('../utils/acceptingMatcher');
5
+ const asMatcher = require('../utils/asMatcher');
6
6
 
7
- const Is = acceptingMatcher((innerMatcher) => {
8
- return _.create(new Matcher(), {
7
+ function Is(valueOrMatcher) {
8
+ const innerMatcher = asMatcher(valueOrMatcher);
9
+ return _create(new Matcher(), {
9
10
  matches: function (actualValue) {
10
11
  return innerMatcher.matches(actualValue);
11
12
  },
@@ -20,7 +21,7 @@ const Is = acceptingMatcher((innerMatcher) => {
20
21
  getExpectedForDiff: innerMatcher.getExpectedForDiff,
21
22
  formatActualForDiff: innerMatcher.formatActualForDiff
22
23
  });
23
- });
24
+ }
24
25
 
25
26
  Is.is = function (innerMatcher) {
26
27
  return new Is(innerMatcher);
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
4
  const Matcher = require('./Matcher');
5
5
 
6
6
  function IsAnything() {
7
- return _.create(new Matcher(), {
7
+ return _create(new Matcher(), {
8
8
  matches: function () {
9
9
  return true;
10
10
  },
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
+ const _isArray = require('lodash/isArray');
4
5
  const TypeSafeMatcher = require('./TypeSafeMatcher');
5
6
 
6
7
  function IsArray() {
7
- return _.create(new TypeSafeMatcher(), {
8
+ return _create(new TypeSafeMatcher(), {
8
9
  isExpectedType: function (actual) {
9
- return _.isArray(actual);
10
+ return _isArray(actual);
10
11
  },
11
12
  describeTo: function (description) {
12
13
  description
@@ -1,29 +1,31 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
+ const _every = require('lodash/every');
5
+ const _map = require('lodash/map');
4
6
  const IsArray = require('./IsArray');
5
7
  const asMatcher = require('../utils/asMatcher');
6
8
  const promiseAgnostic = require('./promiseAgnostic');
7
9
 
8
10
  function IsArrayContaining(itemsOrMatchers) {
9
- const matchers = _.map(itemsOrMatchers, asMatcher);
10
- return _.create(new IsArray(), {
11
+ const matchers = _map(itemsOrMatchers, asMatcher);
12
+ return _create(new IsArray(), {
11
13
  matchesSafely: function (actual) {
12
14
  if (actual.length !== matchers.length) {
13
15
  return false;
14
16
  }
15
17
 
16
- const results = _.map(matchers, (matcher, index) => {
18
+ const results = _map(matchers, (matcher, index) => {
17
19
  return matcher.matches(actual[index]);
18
20
  });
19
21
 
20
- return promiseAgnostic.matchesAggregate(results, _.every);
22
+ return promiseAgnostic.matchesAggregate(results, _every);
21
23
  },
22
24
  describeTo: function (description) {
23
25
  description.appendList('[', ', ', ']', matchers);
24
26
  },
25
27
  describeMismatchSafely: function (actual, description) {
26
- const results = _.map(actual, (value, index) => {
28
+ const results = _map(actual, (value, index) => {
27
29
  if (matchers.length > index) {
28
30
  return matchers[index].matches(value);
29
31
  }
@@ -1,17 +1,20 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _clone = require('lodash/clone');
4
+ const _create = require('lodash/create');
5
+ const _forEach = require('lodash/forEach');
6
+ const _map = require('lodash/map');
4
7
  const IsArray = require('./IsArray');
5
8
  const asMatcher = require('../utils/asMatcher');
6
9
 
7
10
  // TODO: Make promise agnostic
8
11
 
9
12
  function ConsumingMatcher(matchers) {
10
- return _.create({}, {
11
- unmatchedMatchers: _.clone(matchers),
13
+ return _create({}, {
14
+ unmatchedMatchers: _clone(matchers),
12
15
  matches: function (actual) {
13
16
  let matched = false;
14
- _.forEach(this.unmatchedMatchers, (matcher, index) => {
17
+ _forEach(this.unmatchedMatchers, (matcher, index) => {
15
18
  if (matcher.matches(actual)) {
16
19
  matched = true;
17
20
  this.unmatchedMatchers.splice(index, 1);
@@ -24,14 +27,14 @@ function ConsumingMatcher(matchers) {
24
27
  }
25
28
 
26
29
  const IsArrayContainingInAnyOrder = function IsArrayContainingInAnyOrder(itemsOrMatchers) {
27
- const matchers = _.map(itemsOrMatchers, asMatcher);
28
- return _.create(new IsArray(), {
30
+ const matchers = _map(itemsOrMatchers, asMatcher);
31
+ return _create(new IsArray(), {
29
32
  matchesSafely: function (actual) {
30
33
  if (actual.length !== matchers.length) {
31
34
  return false;
32
35
  }
33
36
  const matcher = new ConsumingMatcher(matchers);
34
- _.forEach(actual, (item) => {
37
+ _forEach(actual, (item) => {
35
38
  if (!matcher.matches(item)) {
36
39
  return false;
37
40
  }
@@ -46,7 +49,7 @@ const IsArrayContainingInAnyOrder = function IsArrayContainingInAnyOrder(itemsOr
46
49
  describeMismatchSafely: function (actual, description) {
47
50
  const matcher = new ConsumingMatcher(matchers);
48
51
  const unmatchedItems = [];
49
- _.forEach(actual, (item) => {
52
+ _forEach(actual, (item) => {
50
53
  if (!matcher.matches(item)) {
51
54
  unmatchedItems.push(item);
52
55
  }
@@ -1,14 +1,15 @@
1
1
  'use strict';
2
2
 
3
- const _ = require('lodash');
3
+ const _create = require('lodash/create');
4
+ const _reduce = require('lodash/reduce');
4
5
  const IsArray = require('./IsArray');
5
6
 
6
7
  function IsArrayOrderedBy(comp, compDescription) {
7
8
  compDescription = compDescription || comp.name;
8
- return _.create(new IsArray(), {
9
+ return _create(new IsArray(), {
9
10
  matchesSafely: function (actual) {
10
11
  let correctOrder = true;
11
- _.reduce(actual, (previous, element) => {
12
+ _reduce(actual, (previous, element) => {
12
13
  if (!comp(previous, element)) {
13
14
  correctOrder = false;
14
15
  }
@@ -24,7 +25,7 @@ function IsArrayOrderedBy(comp, compDescription) {
24
25
  describeMismatchSafely: function (actual, description) {
25
26
  let correctOrder = true;
26
27
  let firstMismatch;
27
- _.reduce(actual, (previous, element, index) => {
28
+ _reduce(actual, (previous, element, index) => {
28
29
  if (!comp(previous, element) && correctOrder) {
29
30
  correctOrder = false;
30
31
  firstMismatch = {