Skip to content

content.forEach is not a function when loading node that is not a root #1577

@NeverBehave

Description

@NeverBehave

I don't know whether is it an undocumented behavior or not, when trying to load a node that is not a root, cheerio will try to parse it as a list of nodes.

I believe this commit cause such break: 2e75c2a#diff-cc0e533610b6395aec57bad8971c3692fbf20950660cc5aa5014e58333a738baR28

Minimal Example

similar usage https://stackoverflow.com/questions/39044690/cheerio-map-strange-behaviour

const cheerio = require('cheerio');
const html = `
    <div class="test">
        <div></div>
        <div></div>
    <div>
`

cheerio.load(html)('.test').map((i, e) => {
    cheerio.load(e) // Break, not a root and not an array
})

If this is the desired behavior, what are the alternative ways to workaround this? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions