Skip to content

Commit

Permalink
Handle duplicates of the allowed values
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnikolaj committed Sep 9, 2020
1 parent 9ccabd9 commit 45a97a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/assertions.js
Expand Up @@ -786,7 +786,15 @@ module.exports = (expect) => {
);
});
if (expect.flags.only) {
expect(subject.length, 'to be', args.length);
expect(
subject &&
Array.prototype.every.call(subject, (item) =>
Array.prototype.some.call(args, (arg) =>
expect.equal(item, arg)
)
),
'to be truthy'
);
}
},
(e) => {
Expand Down
11 changes: 11 additions & 0 deletions test/assertions/to-contain.spec.js
Expand Up @@ -179,6 +179,17 @@ describe('to contain assertion', () => {
}, 'not to throw');
});

it('should not throw when all items are included in the subject and some multiple times', () => {
expect(function () {
expect(
[{ bar: 456 }, { foo: 123 }, { bar: 456 }],
'to only contain',
{ foo: 123 },
{ bar: 456 }
);
}, 'not to throw');
});

it('should throw when all items are not included in the subject', () => {
expect(
function () {
Expand Down

0 comments on commit 45a97a8

Please sign in to comment.