Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement iterable assertion #1592

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Consider string to be iterable
  • Loading branch information
koddsson committed Jan 28, 2024
commit 6b8c0cd8886c2e2a76eb9ee19e8ac33cd31dee6a
7 changes: 3 additions & 4 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function an (type, msg) {
);
} else if (type === 'iterable') {
this.assert(
typeof obj !== 'string' && obj != undefined && obj[Symbol.iterator]
obj != undefined && obj[Symbol.iterator]
, 'expected #{this} to be ' + article + type
, 'expected #{this} not to be ' + article + type
);
Expand Down Expand Up @@ -3180,15 +3180,14 @@ Assertion.addMethod('members', function (subset, msg) {
/**
* ### .iterable
*
* Asserts that the target is an iterable, which means that it has a iterator
* with the exception of `String.`
* Asserts that the target is an iterable, which means that it has a iterator.
*
* expect([1, 2]).to.be.iterable;
*
* Add `.not` earlier in the chain to negate `.iterable`.
*
* expect(1).to.not.be.iterable;
* expect("foobar").to.not.be.iterable;
* expect(true).to.not.be.iterable;
*
* A custom error message can be given as the second argument to `expect`.
*
Expand Down
5 changes: 1 addition & 4 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2379,15 +2379,12 @@ describe('assert', function () {
assert.isIterable([1, 2, 3]);
assert.isIterable(new Map([[1, 'one'], [2, 'two'], [3, 'three']]));
assert.isIterable(new Set([1, 2, 3]));
assert.isIterable('hello');

err(function() {
assert.isIterable(42);
}, 'expected 42 to be an iterable');

err(function() {
assert.isIterable('hello');
}, "expected 'hello' to be an iterable");

err(function() {
assert.isIterable(undefined);
}, 'expected undefined to be an iterable');
Expand Down
5 changes: 1 addition & 4 deletions test/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3645,15 +3645,12 @@ describe('expect', function () {
expect([1, 2, 3]).to.be.iterable;
expect(new Map([[1, 'one'], [2, 'two'], [3, 'three']])).to.be.iterable;
expect(new Set([1, 2, 3])).to.be.iterable;
expect('hello').to.be.iterable;

err(function() {
expect(42).to.be.iterable;
}, 'expected 42 to be an iterable');

err(function() {
expect('hello').to.be.iterable;
}, "expected 'hello' to be an iterable");

err(function() {
expect(undefined).to.be.iterable;
}, 'expected undefined to be an iterable');
Expand Down
5 changes: 1 addition & 4 deletions test/should.js
Original file line number Diff line number Diff line change
Expand Up @@ -2946,15 +2946,12 @@ describe('should', function() {
([1, 2, 3]).should.be.iterable;
(new Map([[1, 'one'], [2, 'two'], [3, 'three']])).should.be.iterable;
(new Set([1, 2, 3])).should.be.iterable;
('hello').should.be.iterable;

err(function() {
(42).should.be.iterable;
}, 'expected 42 to be an iterable');

err(function() {
('hello').should.be.iterable;
}, "expected 'hello' to be an iterable");

err(function() {
(true).should.be.iterable;
}, 'expected true to be an iterable');
Expand Down