busterjs / buster

Abandoned - A powerful suite of automated test tools for JavaScript.
http://docs.busterjs.org
Other
448 stars 37 forks source link

`assert.match` should not be calling every method on an object it's matching against #436

Closed dominykas closed 6 years ago

dominykas commented 9 years ago

This is in the light of reviewing results of the fix for https://github.com/busterjs/buster/issues/64

assert.match will try to use assert.match on every property of the objects. Which means that if said property is a function - it will call assert.match(actualObj[someProp], expectedObj[someProp]). If expectedObj[someProp] is a function, match will call that function: var fn = expectedObj[someProp]; fn(actualObj[someProp])... That's just a bad idea, as you may imagine :)

Just opening up a discussion for now. Head is busy with too many things, to suggest a good solution for now.

dominykas commented 9 years ago

Had a quick look and figured hey - if and object's method is the same, then it matches, and if it isn't - then it doesn't. But apparently all functions are treated as matchers, even when they're nested: https://github.com/dominykas/samsam/blob/master/test/samsam-test.js#L326

I could implement it so that if the matcher property is a function, and the object property is a function, and they're both the same function - it matches, and if it's not the same function - use it as a matcher. But wouldn't this be kind of too magic?

In short the options are:

  1. Do magic
  2. Break existing behaviour of nested matchers
  3. Close this as won't fix
dominykas commented 6 years ago

stalebot-ing myself.