diff --git a/lib/jasmine-jquery.js b/lib/jasmine-jquery.js index 266bf67c..5eeb38f3 100644 --- a/lib/jasmine-jquery.js +++ b/lib/jasmine-jquery.js @@ -512,11 +512,18 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. var actualText = $(actual).text() var trimmedText = $.trim(actualText) + var result; if (text && $.isFunction(text.test)) { - return { pass: text.test(actualText) || text.test(trimmedText) } + result = { pass: text.test(actualText) || text.test(trimmedText) } } else { - return { pass: (actualText == text || trimmedText == text) } + result = { pass: (actualText == text || trimmedText == text) } } + + result.message = result.pass ? + "Expected element '" + $(actual).html() + "' not to have text " + text : + "Expected element '" + $(actual).html() + "' to have text " + text; + + return result; } } }, @@ -554,7 +561,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. toContainElement: function () { return { compare: function (actual, selector) { - return { pass: $(actual).find(selector).length } + var result = { pass: $(actual).find(selector).length }; + + result.message = result.pass ? + "Expected element '" + $(actual).html() + "' not to have element " + selector : + "Expected element '" + $(actual).html() + "' to have element " + selector; + + return result; } } },