moll / js-must

An assertion library for JavaScript and Node.js with a friendly BDD syntax (awesome.must.be.true()). It ships with many expressive matchers and is test runner and framework agnostic. Follows RFC 2119 with its use of MUST. Good stuff and well tested.
Other
336 stars 35 forks source link

Strange issue with Promises and Mocha #55

Closed capelio closed 7 years ago

capelio commented 7 years ago

Using mocha, must, and promises:

it('works as expected', () => {
  return expect(Promise.resolve([1, 2, 3])).to.resolve.to.array()
})

it('throws a TypeError', () => {
  return expect(Promise.resolve([1, 2, 3])).to.resolve.to.be.an.array()
})

And the TypeError:

     TypeError: Function.prototype.toString is not generic
      at Must.toString (native)
      at Function.prepareStackTrace (node_modules/source-map-support/source-map-support.js:365:16)
      at Must.assert (node_modules/must/lib/thenable.js:20:41)
      at apply (node_modules/must/node_modules/lodash.wrap/node_modules/lodash._createwrapper/index.js:72:25)
      at Must.wrapper (node_modules/must/node_modules/lodash.wrap/node_modules/lodash._createwrapper/index.js:415:12)
      at Must.array (node_modules/must/must.js:314:8)
      at Must.exports.then (node_modules/must/lib/thenable.js:26:6)

Maybe I'm reading the docs incorrectly, but this seems like it should work.

moll commented 7 years ago

Hey! Sorry you're facing trouble. I'll take a look!

moll commented 7 years ago

I'm having slight trouble reproducing this. The second example above seems to run under Node v4 and Node v7. I think this is related to the source-map-support plugin. Would you mind telling which version of it are you using? I suspect what's causing it, but I'd like to be certain. Thanks!

capelio commented 7 years ago

Ah, good point. I should have mentioned I'm using babel with mocha, didn't think of it at the time.

A npm ls gives me source-map-support@0.4.6. I'm on Node 4.4.4, npm 2.15.1, and babel-register 6.18.0.

I've run the tests both with and without registering babel to mocha. The TypeError only throws when running with babel registered. Everything's kosher once babel is taken out of the equation.

capelio commented 7 years ago

And by the way, thanks a ton for Must.js. Best assertion library out there :)

moll commented 7 years ago

Thanks for the clarification! I tweaked the implementation of Must.prototype.be. Would you mind installing from master, this repo, and confirm if that fixes it for you. If it does, I'll publish a release.

Thanks for the love, too! What do you particularly like, so I'll know to bring that up when occasionally promoting it? :)

capelio commented 7 years ago

Nicely done! Pulled latest master, ran npm link, pulled it into my project with npm link must, and both tests now pass.

Here's why I love Must:

moll commented 7 years ago

Thanks for confirming and for elaborating! :) Sent v0.13.4 out there. Should really tweak a few other things and release v1. This 0.x thing has gone for far too long. This is not GMail with its infinite beta!