You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document, test, and extend static $.text method (#855)
* Document and test static `text` method
* Extend `$.text()` to operate on current root
Update `$.root` to return the rendered text content of the current root
element when no argument is specified. This increases API parity with
the existing static methods `$.html` and``$.xml`.
This change technically breaks backwards compatability, but the previous
behavior was undocumented and untested.
it('(cheerio object) : should return the text contents of the specified elements',function(){
40
+
var$=cheerio.load('<a>This is <em>content</em>.</a>');
41
+
expect($.text($('a'))).to.equal('This is content.');
42
+
});
43
+
44
+
it('(cheerio object) : should omit comment nodes',function(){
45
+
var$=cheerio.load('<a>This is <!-- a comment --> not a comment.</a>');
46
+
expect($.text($('a'))).to.equal('This is not a comment.');
47
+
});
48
+
49
+
it('(cheerio object) : should include text contents of children recursively',function(){
50
+
var$=cheerio.load('<a>This is <div>a child with <span>another child and <!-- a comment --> not a comment</span> followed by <em>one last child</em> and some final</div> text.</a>');
51
+
expect($.text($('a'))).to.equal('This is a child with another child and not a comment followed by one last child and some final text.');
52
+
});
53
+
54
+
it('() : should return the rendered text content of the root',function(){
55
+
var$=cheerio.load('<a>This is <div>a child with <span>another child and <!-- a comment --> not a comment</span> followed by <em>one last child</em> and some final</div> text.</a>');
56
+
expect($.text()).to.equal('This is a child with another child and not a comment followed by one last child and some final text.');
0 commit comments