MatthewMueller/cheerio — pull request #245 by jugglinmike (2013-07-30 12:50:11+00:00)
Title: Correct behavior of `Cheerio#parents`

As we discovered in issue #229, there is a bug in the implementation of `Cheerio#parents`. When invoked on a top-level element, the method returns the original Cheerio collection. In this case, it should return an empty set.

Correcting this behavior makes `Cheerio#parents` slightly simpler (one less branch) and also improves a ([somewhat dubious-looking](https://github.com/MatthewMueller/cheerio/pull/229#pullrequestreviewcomment-5435741)) [traversal in `Cheerio#val`](https://github.com/MatthewMueller/cheerio/blob/2cac9e48593b485cd908308d13410b95e8b7eaf2/lib/api/attributes.js#L75-L79).

Commit message:

> When invoked on a top-level element, `parents` should return an empty
> set.
>
> Because a unit test for `Cheerio#parents` and the implementation of
> `Cheerio#val` depends on the erroneous behavior, this code must also be
> updated.