diff --git a/documentation/assertions/array-like/to-contain.md b/documentation/assertions/array-like/to-contain.md index cea9b0644..f66661d14 100644 --- a/documentation/assertions/array-like/to-contain.md +++ b/documentation/assertions/array-like/to-contain.md @@ -53,7 +53,7 @@ be in the subject. ```js expect( [{ name: 'John Doe' }, { name: 'Jane Doe' }], - 'to exhaustively contain', + 'to only contain', { name: 'Jane Doe' }, { name: 'John Doe' } ); @@ -65,14 +65,14 @@ following output: ```js expect( [{ name: 'Jane Doe' }, { name: 'John Doe' }], - 'to exhaustively contain', + 'to only contain', { name: 'Jane Doe' } ); ``` ```output expected [ { name: 'Jane Doe' }, { name: 'John Doe' } ] -to exhaustively contain { name: 'Jane Doe' } +to only contain { name: 'Jane Doe' } [ { name: 'Jane Doe' }, diff --git a/lib/assertions.js b/lib/assertions.js index ed8663277..ada3422ba 100644 --- a/lib/assertions.js +++ b/lib/assertions.js @@ -767,14 +767,14 @@ module.exports = (expect) => { }); expect.addAssertion( - ' [not] to [exhaustively] contain ', + ' [not] to [only] contain ', function (expect, subject) { const args = Array.prototype.slice.call(arguments, 2); - if (expect.flags.exhaustively && expect.flags.not) { + if (expect.flags.only && expect.flags.not) { expect.errorMode = 'bubble'; expect.fail( - 'The "not" flag cannot be used together with "to exhaustively contain".' + 'The "not" flag cannot be used together with "to only contain".' ); } @@ -789,7 +789,7 @@ module.exports = (expect) => { '[not] to be truthy' ); }); - if (expect.flags.exhaustively) { + if (expect.flags.only) { expect(subject.length, 'to be', args.length); } }, @@ -804,7 +804,7 @@ module.exports = (expect) => { (item) => !args.some((arg) => equal(item, arg)) ) ); - } else if (expect.flags.exhaustively) { + } else if (expect.flags.only) { var excessItems = Array.prototype.filter.call(subject, (item) => args.some((arg) => equal(item, arg)) ); diff --git a/test/assertions/to-contain.spec.js b/test/assertions/to-contain.spec.js index 184f1d872..62e62626e 100644 --- a/test/assertions/to-contain.spec.js +++ b/test/assertions/to-contain.spec.js @@ -32,7 +32,7 @@ describe('to contain assertion', () => { ' The assertion does not have a matching signature for:\n' + ' not to contain \n' + ' did you mean:\n' + - ' [not] to [exhaustively] contain \n' + + ' [not] to [only] contain \n' + ' [not] to contain ' ); @@ -80,7 +80,7 @@ describe('to contain assertion', () => { ' The assertion does not have a matching signature for:\n' + ' to contain \n' + ' did you mean:\n' + - ' [not] to [exhaustively] contain \n' + + ' [not] to [only] contain \n' + ' [not] to contain ' ); }); @@ -166,12 +166,12 @@ describe('to contain assertion', () => { }); }); - describe('with the exhaustively flag', () => { + describe('with the only flag', () => { it('should not throw when all items are included in the subject', () => { expect(function () { expect( [{ bar: 456 }, { foo: 123 }], - 'to exhaustively contain', + 'to only contain', { foo: 123 }, { bar: 456 } ); @@ -183,13 +183,13 @@ describe('to contain assertion', () => { function () { expect( [{ bar: 456 }], - 'to exhaustively contain', + 'to only contain', { foo: 123 }, { bar: 456 } ); }, 'to throw exception', - 'expected [ { bar: 456 } ] to exhaustively contain { foo: 123 }, { bar: 456 }\n' + + 'expected [ { bar: 456 } ] to only contain { foo: 123 }, { bar: 456 }\n' + '\n' + '[\n' + ' { bar: 456 }\n' + @@ -203,14 +203,14 @@ describe('to contain assertion', () => { function () { expect( [{ bar: 456 }, { foo: 123 }, { baz: 789 }], - 'to exhaustively contain', + 'to only contain', { foo: 123 }, { bar: 456 } ); }, 'to throw exception', 'expected [ { bar: 456 }, { foo: 123 }, { baz: 789 } ]\n' + - 'to exhaustively contain { foo: 123 }, { bar: 456 }\n' + + 'to only contain { foo: 123 }, { bar: 456 }\n' + '\n' + '[\n' + ' { bar: 456 },\n' + @@ -220,13 +220,13 @@ describe('to contain assertion', () => { ); }); - it('should throw when combining the not and exhaustively flags', () => { + it('should throw when combining the not and only flags', () => { expect( function () { - expect([{ foo: 123 }], 'not to exhaustively contain', { foo: 123 }); + expect([{ foo: 123 }], 'not to only contain', { foo: 123 }); }, 'to throw exception', - 'The "not" flag cannot be used together with "to exhaustively contain".' + 'The "not" flag cannot be used together with "to only contain".' ); }); });