Skip to content

Commit

Permalink
Rename exhaustively flag to only
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnikolaj committed Sep 8, 2020
1 parent dfd6a7f commit 30d2581
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions documentation/assertions/array-like/to-contain.md
Expand Up @@ -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' }
);
Expand All @@ -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' },
Expand Down
10 changes: 5 additions & 5 deletions lib/assertions.js
Expand Up @@ -767,14 +767,14 @@ module.exports = (expect) => {
});

expect.addAssertion(
'<array-like> [not] to [exhaustively] contain <any+>',
'<array-like> [not] to [only] contain <any+>',
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".'
);
}

Expand All @@ -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);
}
},
Expand All @@ -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))
);
Expand Down
22 changes: 11 additions & 11 deletions test/assertions/to-contain.spec.js
Expand Up @@ -32,7 +32,7 @@ describe('to contain assertion', () => {
' The assertion does not have a matching signature for:\n' +
' <null> not to contain <string>\n' +
' did you mean:\n' +
' <array-like> [not] to [exhaustively] contain <any+>\n' +
' <array-like> [not] to [only] contain <any+>\n' +
' <string> [not] to contain <string+>'
);

Expand Down Expand Up @@ -80,7 +80,7 @@ describe('to contain assertion', () => {
' The assertion does not have a matching signature for:\n' +
' <number> to contain <number>\n' +
' did you mean:\n' +
' <array-like> [not] to [exhaustively] contain <any+>\n' +
' <array-like> [not] to [only] contain <any+>\n' +
' <string> [not] to contain <string+>'
);
});
Expand Down Expand Up @@ -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 }
);
Expand All @@ -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' +
Expand All @@ -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' +
Expand All @@ -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".'
);
});
});
Expand Down

0 comments on commit 30d2581

Please sign in to comment.