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

isIterable() has a case of false positives. #19

Open
segayuu opened this issue May 2, 2018 · 0 comments
Open

isIterable() has a case of false positives. #19

segayuu opened this issue May 2, 2018 · 0 comments

Comments

@segayuu
Copy link

segayuu commented May 2, 2018

iterable must have an [@@iterator]() method and its return value must be an iterator.
iterator must have an next() method and its return value must be an iteratorResult.
iteratorResult is an object, it must have a boolean done property, and when done property is false, value property must be present.

In other words, if chai really say iterable, it should be possible to get iteratorResult!

It is difficult to obtain iteratorResult on the premise that there are no side effects. (Ex: queue, stack)
However, when calling [@@iterator]() it is very uncommon case that there are side effects other than for debugging purposes.

if (!(value != null && typeof value[Symbol.iterator] === 'function')) {
  return false;
}
const maybeIterator = value[Symbol.iterator]();
if (typeof maybeIterator !== 'object' || typeof maybeIterator.next !== 'function') {
  return false;
}
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant