Testing Wisdom

I’ve run into a problem where the DOM of Chrome and Firefox return different HTML results where they rearrange the attributes of elements when jQuery.html stringifys them. Don’t fight it outright with writing a bunch of code to check the existence of attribute values, etc.

Just write a “satisfies” assertion and get on with your day:

chai.expect(html).to.satisfy(
function(x) {
return (x === '<div a="1" b="2"></div>' 
     || x === '<div b="2" a="1"></div>'
   )
})

If the other browsers you’re testing in also give you grief, it is still probably easier (and faster) to just add to the satisfy’s clause than try to do a more sophisticated match.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s