Skip to content

Commit

Permalink
Consider string to be iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Jan 28, 2024
1 parent c0e6dd7 commit 6b8c0cd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
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

0 comments on commit 6b8c0cd

Please sign in to comment.