在 jquery-jasmine documentation (我列出了文档的确切修订版本,以防它们发生更改)。
它描述了:
toContainHtml(字符串)
expect($('<div><ul></ul><h1>header</h1></div>')).toContainHtml('<ul></ul>')
toHaveHtml(字符串)
expect($('<div><span></span></div>')).toHaveHtml('<span></span>')
什么时候应该使用 toContainHtml() 以及什么时候应该使用 toHaveHtml()?从示例中我看不出区别。
最佳答案
据此判断ticket on jasmine-jquery's github page
toHaveHtml() 使用 ==
检查更加精确
而 toContainHtml() 使用 indexOf()
检查。
但是文档中的示例并没有真正证明这一点,所以我仍然不确定。
关于jasmine - jasmine-jquery 中的 toContainHtml() 与 toHaveHtml(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22350664/