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

Set support in same members #1583

Merged
merged 9 commits into from
Feb 12, 2024
Next Next commit
Implement iterator assertion
  • Loading branch information
koddsson committed Feb 11, 2024
commit 76095807f6fed9e51eafb7824ed5a3bf0e055ff2
11 changes: 10 additions & 1 deletion lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ function an (type, msg) {
, 'expected #{this} to be ' + article + type
, 'expected #{this} not to be ' + article + type
);
} else if (type === 'iterable') {
koddsson marked this conversation as resolved.
Show resolved Hide resolved
this.assert(
typeof obj !== 'string' && obj != undefined && obj[Symbol.iterator]
, 'expected #{this} to be ' + article + type
, 'expected #{this} not to be ' + article + type
);
} else {
this.assert(
type === detectedType
Expand Down Expand Up @@ -3037,7 +3043,9 @@ Assertion.addMethod('closeTo', closeTo);
Assertion.addMethod('approximately', closeTo);

// Note: Duplicates are ignored if testing for inclusion instead of sameness.
function isSubsetOf(subset, superset, cmp, contains, ordered) {
function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
let superset = Array.from(_superset);
let subset = Array.from(_subset);
koddsson marked this conversation as resolved.
Show resolved Hide resolved
if (!contains) {
if (subset.length !== superset.length) return false;
superset = superset.slice();
Expand Down Expand Up @@ -3175,6 +3183,7 @@ Assertion.addMethod('members', function (subset, msg) {
* Asserts that the target is an iterable, which means that it has a iterator.
*
* expect([1, 2]).to.be.iterable;
* expect("foobar").to.be.iterable;
*
* Add `.not` earlier in the chain to negate `.iterable`.
*
Expand Down