Skip to content

Commit

Permalink
Merge pull request #348 from unexpectedjs/feature/disallowAnyPlus
Browse files Browse the repository at this point in the history
to have (items|values|keys) satisfying: Only allow one <any> as the value, not <any+>
  • Loading branch information
papandreou committed Nov 18, 2016
2 parents d4fb296 + 02a183c commit 92cc275
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/assertions.js
Expand Up @@ -694,9 +694,9 @@ module.exports = function (expect) {
});

expect.addAssertion([
'<object> to have values [exhaustively] satisfying <any+>',
'<object> to have values [exhaustively] satisfying <any>',
'<object> to have values [exhaustively] satisfying <assertion>',
'<object> to be (a map|a hash|an object) whose values [exhaustively] satisfy <any+>',
'<object> to be (a map|a hash|an object) whose values [exhaustively] satisfy <any>',
'<object> to be (a map|a hash|an object) whose values [exhaustively] satisfy <assertion>'
], function (expect, subject, nextArg) {
expect.errorMode = 'nested';
Expand Down Expand Up @@ -739,9 +739,9 @@ module.exports = function (expect) {
});

expect.addAssertion([
'<array-like> to have items [exhaustively] satisfying <any+>',
'<array-like> to have items [exhaustively] satisfying <any>',
'<array-like> to have items [exhaustively] satisfying <assertion>',
'<array-like> to be an array whose items [exhaustively] satisfy <any+>',
'<array-like> to be an array whose items [exhaustively] satisfy <any>',
'<array-like> to be an array whose items [exhaustively] satisfy <assertion>'
], function (expect, subject) { // ...
var extraArgs = Array.prototype.slice.call(arguments, 2);
Expand All @@ -766,9 +766,9 @@ module.exports = function (expect) {
});

expect.addAssertion([
'<object> to have keys satisfying <any+>',
'<object> to have keys satisfying <any>',
'<object> to have keys satisfying <assertion>',
'<object> to be (a map|a hash|an object) whose (keys|properties) satisfy <any+>',
'<object> to be (a map|a hash|an object) whose (keys|properties) satisfy <any>',
'<object> to be (a map|a hash|an object) whose (keys|properties) satisfy <assertion>'
], function (expect, subject) {
var extraArgs = Array.prototype.slice.call(arguments, 2);
Expand Down
14 changes: 12 additions & 2 deletions test/assertions/to-have-items-satisfying.spec.js
Expand Up @@ -6,7 +6,17 @@ describe('to have items satisfying assertion', function () {
}, 'to throw',
"expected [ 1, 2, 3 ] to have items satisfying\n" +
" No matching assertion, did you mean:\n" +
" <array-like> to have items [exhaustively] satisfying <any+>\n" +
" <array-like> to have items [exhaustively] satisfying <any>\n" +
" <array-like> to have items [exhaustively] satisfying <assertion>");
});

it('does not accept a fourth argument', function () {
expect(function () {
expect([1], 'to have items satisfying', 1, 2);
}, 'to throw',
"expected [ 1 ] to have items satisfying 1, 2\n" +
" No matching assertion, did you mean:\n" +
" <array-like> to have items [exhaustively] satisfying <any>\n" +
" <array-like> to have items [exhaustively] satisfying <assertion>");
});

Expand All @@ -16,7 +26,7 @@ describe('to have items satisfying assertion', function () {
}, 'to throw',
"expected 42 to have items satisfying function (item) {}\n" +
" No matching assertion, did you mean:\n" +
" <array-like> to have items [exhaustively] satisfying <any+>\n" +
" <array-like> to have items [exhaustively] satisfying <any>\n" +
" <array-like> to have items [exhaustively] satisfying <assertion>");
});

Expand Down
14 changes: 12 additions & 2 deletions test/assertions/to-have-keys-satisfying.spec.js
Expand Up @@ -6,7 +6,17 @@ describe('to have keys satisfying assertion', function () {
}, 'to throw',
"expected [ 1, 2, 3 ] to have keys satisfying\n" +
" No matching assertion, did you mean:\n" +
" <object> to have keys satisfying <any+>\n" +
" <object> to have keys satisfying <any>\n" +
" <object> to have keys satisfying <assertion>");
});

it('does not accept a fourth argument', function () {
expect(function () {
expect([1], 'to have keys satisfying', 0, 1);
}, 'to throw',
"expected [ 1 ] to have keys satisfying 0, 1\n" +
" No matching assertion, did you mean:\n" +
" <object> to have keys satisfying <any>\n" +
" <object> to have keys satisfying <assertion>");
});

Expand All @@ -16,7 +26,7 @@ describe('to have keys satisfying assertion', function () {
}, 'to throw',
"expected 42 to have keys satisfying function (key) {}\n" +
" No matching assertion, did you mean:\n" +
" <object> to have keys satisfying <any+>\n" +
" <object> to have keys satisfying <any>\n" +
" <object> to have keys satisfying <assertion>");
});

Expand Down
14 changes: 12 additions & 2 deletions test/assertions/to-have-values-satisfying.spec.js
Expand Up @@ -6,7 +6,17 @@ describe('to have values satisfying assertion', function () {
}, 'to throw',
"expected [ 1, 2, 3 ] to have values satisfying\n" +
" No matching assertion, did you mean:\n" +
" <object> to have values [exhaustively] satisfying <any+>\n" +
" <object> to have values [exhaustively] satisfying <any>\n" +
" <object> to have values [exhaustively] satisfying <assertion>");
});

it('does not accept a fourth argument', function () {
expect(function () {
expect([1], 'to have values satisfying', 1, 2);
}, 'to throw',
"expected [ 1 ] to have values satisfying 1, 2\n" +
" No matching assertion, did you mean:\n" +
" <object> to have values [exhaustively] satisfying <any>\n" +
" <object> to have values [exhaustively] satisfying <assertion>");
});

Expand All @@ -16,7 +26,7 @@ describe('to have values satisfying assertion', function () {
}, 'to throw',
"expected 42 to have values satisfying function (value) {}\n" +
" No matching assertion, did you mean:\n" +
" <object> to have values [exhaustively] satisfying <any+>\n" +
" <object> to have values [exhaustively] satisfying <any>\n" +
" <object> to have values [exhaustively] satisfying <assertion>");
});

Expand Down

0 comments on commit 92cc275

Please sign in to comment.