In the jquery-jasmine documentation (I've listed the exact revision of the docs in case they change).

It describes:

toContainHtml(string)

expect($('<div><ul></ul><h1>header</h1></div>')).toContainHtml('<ul></ul>')

toHaveHtml(string)

expect($('<div><span></span></div>')).toHaveHtml('<span></span>')

When should I use toContainHtml() and when should I use toHaveHtml()? From the examples I can't tell the difference.

有帮助吗?

解决方案

Judging by this ticket on jasmine-jquery's github page

toHaveHtml() is more exacting using a == check

Whereas toContainHtml() uses an indexOf() check.

However the example in the documentation doesn't really demonstrate this, so I'm still not certain.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top