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

Feature request: don't automatically extend object prototypes #35

Closed cappslock closed 8 years ago

cappslock commented 8 years ago

I like using the demand() syntax style and would prefer not to modify the prototype chain of language primitives. Unfortunately there's no way to do this with must currently, which is a deal-breaker for me.

Would you consider offering a version of this which can be used in the demand(thing).to.be.true() which does not still enable the thing.must.be.true() syntax? Chai seems to be able to do this, but I'd prefer to use must for the reasons you already know about :)

moll commented 8 years ago

Hey. Absolutely. I've already made the necessary accommodations, but haven't disabled Object.prototype.must by default because of backwards compatibility. It'll be optional in v1, but till then you can either just delete Object.prototype.must in your test/index.js and load it with mocha.opts (https://github.com/moll/js-must#autoloading) or load the must.js file directly: require("must/must"). The latter doesn't "register" the global even in <v1. The default is must/register.

moll commented 8 years ago

I updated the other examples in the README to use must/register to future-proof people new to Must.js. ;-)

cappslock commented 8 years ago

Wonderful, thank you!

cappslock commented 8 years ago

Fun fact, I'm not even using this for testing currently, just verifying arguments and preconditions in functions to prevent pernicious bugs.

moll commented 8 years ago

Hehe, indeed, I've thought about how to make Must more amenable to use outside of testing, too.

I'm leaning towards we're just using an overly weak language and should look for more type-safe languages to save a bunch of effort doing runtime checks. ^_^

moll commented 8 years ago

I'll close this issue for now, though we can carry on conversing. ;)

cappslock commented 8 years ago

Would you consider reopening this until this is implemented?

cappslock commented 8 years ago

Mainly so that, when you close it, I know I can switch to Must :)