How to use the cheerio.dom function in cheerio

To help you get started, we’ve selected a few cheerio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matthewmueller / cheerio-select / test / select.name.js View on Github external
it('should handle complex insertions', function() {
    var a = cheerio('<div><a name="tName1" id="tName1ID">tName1 A</a><a name="tName2" id="tName2ID">tName2 A</a><div id="tName1">tName1 Div</div></div>');
    cheerio('#qunit-fixture').append(a);
    a = a.children();

    expect(a).to.have.length(3);
    expect(a[1].attribs.id).to.equal('tName2ID');

    // A little crazy.. basically test if new dom contains inserted elems
    expect($("[name=tName1]", cheerio.dom())[0]).to.equal(a[0]);
    expect($("[name=tName2]", cheerio.dom())[0]).to.equal(a[1]);
    expect($('#tName2ID', cheerio.dom())).to.have.length(1);

    a.remove();
  });
});