mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-05 08:46:53 +08:00
unexport SetNodes, add SetHtml tests
This commit is contained in:
@@ -281,7 +281,7 @@ func TestReplaceWithHtml(t *testing.T) {
|
||||
func TestSetHtml(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
q := doc.Find("#main, #foot")
|
||||
q.SetHtml("<div id=\"replace\">test</div>")
|
||||
q.SetHtml(`<div id="replace">test</div>`)
|
||||
|
||||
assertLength(t, doc.Find("#replace").Nodes, 2)
|
||||
assertLength(t, doc.Find("#main, #foot").Nodes, 2)
|
||||
@@ -293,6 +293,26 @@ func TestSetHtml(t *testing.T) {
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestSetHtmlNoMatch(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
q := doc.Find("#notthere")
|
||||
q.SetHtml(`<div id="replace">test</div>`)
|
||||
|
||||
assertLength(t, doc.Find("#replace").Nodes, 0)
|
||||
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestSetHtmlEmpty(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
q := doc.Find("#main")
|
||||
q.SetHtml(``)
|
||||
|
||||
assertLength(t, doc.Find("#main").Nodes, 1)
|
||||
assertLength(t, doc.Find("#main").Children().Nodes, 0)
|
||||
printSel(t, doc.Selection)
|
||||
}
|
||||
|
||||
func TestSetText(t *testing.T) {
|
||||
doc := Doc2Clone()
|
||||
q := doc.Find("#main, #foot")
|
||||
|
Reference in New Issue
Block a user