Thanks to Tobias' answer I ended up improving on that and wrote my own custom matcher. Now I can write:
expect( $('#users').find('tbody tr').first() ).toHaveNormalizedText('Darren testuser,customer today');
Matcher code -- added in the beforeEach() block of my describe() scenario:
this.addMatchers({
toHaveNormalizedText: function(expected) {
var actualText = $.trim(this.actual.text()).replace(/\s+/g, ' ');
var result = actualText === expected;
if( result) return result;
//rest is only if it fails
var notText = this.isNot ? " not" : "";
var charcodes = [];
for(var i=0; i<actualText.length; i++){
charcodes.push(actualText.charCodeAt(i));
if(i>23) break;
}
this.message = function () {return 'Expected "' + actualText + notText + '" to match "'+expected+'"\n\nFirst 25 charcodes:\n'+charcodes;};
return result;
}
});
A few notes about this. Here is the actual replacement:
$.trim(this.actual.text()).replace(/\s+/g, ' ');
$.trim() was important for my html structure which did include whitespace in the beginning of the text() string.
this.message = function () {return 'Expected "' + actualText + notText + '" to match "'+expected+'"\n\nFirst 25 charcodes:\n'+charcodes;};
this.message
is jasmine's custom error message. This string outputs strings like this on error:
failed
Expected "Darren testuser,customer todaiiy" to match "Darren testuser,customer today"
First 25 charcodes:
68,97,114,114,101,110,32,116,101,115,116,117,115,101,114,44,99,117,115,116,111,109,101,114,32 (1)
I decided to add the charcodes because at one point I had a problem with charcodes 10 (newline) and 32 (spaces).