-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there are plugin structure planned? #12
Comments
Hi, the easiest and quickest way is to create a (or several) standard module and use it in your tests. If you want a multi API styles as Chai with Must.js assertions, you can look Unit.js (most assertions are made on top of Must.js, it also embeds other libraries of assertions for more specific things such as HTTP request testing, mock, ...). Then you might consider creating your plugins in a simple object : test.isUsername = function(){
test.must(test.actual).between(2, 10);
test.must(test.actual).match(/[a-zA-Z0-9]/);
return test;
}; In your tests suite : // pass
test.string('foo').isUsername();
// fail because not match with the regex pattern [a-zA-Z0-9]
test.string('foo@bar').isUsername();
// fail, because is not between 2, 10
test.string('f').isUsername();
// fail, because is not between 2, 10
test.string('foooooooooooooooooooo').isUsername(); |
Hey, @pscheit! I do have a plan to expose an internal function that Must itself uses for asserting and creating assertion errors — that would help writing custom assertions/plugins on the Were you mostly interested in adding your own assertions to Must's namespace that you could then call in the form of You should, however, be able to try something out right away by using the existing assertions. The stack trace your test runner will show (e.g. Mocha) will be a little misleading, though, as it will show that assertion function as the source of failure. Must.prototype.awesome = function() { this.actual.must.equal("awesome") }
"Something".must.be.awesome() Thanks, @Nicolab, for pitching in, too! :) |
Hello, a suggestion : Must.register('awesome', assertion, 'error message', diff); Parameters : 'awesome' : assertion identification that produce must.awesome() assertion : callback for asserting 'error message : (optional) a custom message if the assertion fails (or optionally accept a callback ?) diff : (optional) a custom callback for the diff between actual / expected (if the assertion fails) Something in the style :) |
Good news, everyone! Made some progress:
Given the above, to add matchers, one could just assign them to Thanks in advance! |
Let us know when you publish these so we can start working on our plugins. |
Will do. I'm kind of waiting for your feedback first actually to know if it does the trick or needs something further. :-) |
I'll start working on another plugin tomorrow morning. |
@moll, check out must-sinon. I still have a few matchers to add, but the basic plugin functionality is in place and working. So, AFAICT ... Must.js is plugin ready. :-) |
Checking it out now. You gave me an idea with those placeholder vars — perhaps rather than always concatenating |
Using placeholders seems like a good idea to me. :-) |
They might indeed, but I've got a sneaky feeling we should start with no interpolation nor concatenating initially. The risk with more features off the bat is that it might prevent something better designed later. |
I understand your concern. The upside is that interpolation would allow you to construct a more readable message, since you can interpolate the That said, you're in a much better position to gauge whether a feature like this may or may not hinder future features/design. |
The stringifying function Must uses for concatenation is currently exported as |
Yeah ... didn't realize until now that you've exported |
My bad. Haven't documented the developer facing API. |
@moll I went ahead and gave it a shoot with Targaryen plugin called must-targaryen. Could you take a look and give any suggestions if something looks wrong? |
I've added another to the mix for JSX comparison - must-jsx. |
Thanks @JohnnyEstilles, @jtwebman and @nwinch for pitching in. I linked to the three modules above in the README: https://github.com/moll/js-must#plugins. 👍 everyone for exporting a function to be called with I'll close this issue as tweaking Must for extensibility is an ongoing task. So far |
Hey there, your attempt to write another assertion library sounds compromising.
Are you planning to write a plugin structure like in chai? I have a lot of complex tests and would love to have something "easier" than the chaijs plugin structure. Maybe something more intuitive ;)
best regards and thank you
philipp
The text was updated successfully, but these errors were encountered: