-
Notifications
You must be signed in to change notification settings - Fork 142
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
Getting testdouble.js to play nicely with Jasmine expectations? #41
Comments
My first instinct was to say that I didn't want a custom matcher... but that actually works out pretty well: jasmine.addMatchers({
toVerify: function() {
return {
compare: function(doubleCall) {
try {
td.verify(doubleCall);
return { pass: true };
} catch(e) {
return {
pass: false,
message: e.message
}
}
}
};
}
}); Then instead of td.verify(test.dependency.fiddle({a: 'jake', b: 'stuff', c: 99})); It becomes expect().toVerify(test.dependency.fiddle({a: 'jake', b: 'stuff', c: 99})); |
seems legit. How would you want to incorporate this is an adaptable way to For instance, jasmine1, jasmine2, chai, all have separate custom matcher Maybe On Mon, Oct 26, 2015 at 8:30 AM Brian Genisio notifications@github.com
|
A similar idea was brought up by Casey Brant in his blog post responding to testdouble.js. I responded here: https://github.com/BaseCase/trying_out_test_double/issues/1 (the suggestion being to create a separate library that acts as a bridge between testdouble.js and the assertion lib) Given a few common such bridges, they might be useful in a contrib/ section or something. However, in this particular case I'm curious how jasmine-given gets around this. jasmine-given doesn't define any expectations (that I know of). Rather, it's raise-exception or pass. Is something other than Jasmine core doing this? |
I don't know... seems like keeping testdouble.js agnostic is fine. I wasn't really opening an issue to suggest a change to the lib. (I wish GitHub had a "questions" mechanism). A Wiki page that includes some integration notes might be all that you need. |
@jasonkarns jasmine-given uses my jasmine-matchers-wrapper to add matchers regardless of jasmine1 or jasmine2 (i would recommend using the same in this case). Link to usage: https://github.com/searls/jasmine-given/blob/master/app/js/jasmine-given.coffee#L207-L210 |
All this time and I never knew that every |
Hi @BrianGenisio, I've done something pretty similar to what you posted above (edit to add: for chai, not for Jasmine, but same idea), but as a separate little library in https://github.com/BaseCase/testdouble-chai. I was able to get it plugged in nicely with normal test runner output, sans distracting console printing. Not sure if that's useful to you or not, but feel free to copy/paste if it's helpful for your Jasmine matcher! :) |
& I recommend we do something exactly like testdouble-chai. A testdouble-jasmine module that receives both jasmine & test double as injected dependencies, and which sets up a toHaveBeenCalled-like matcher that is in line with to verify's signature (method, args, options) on either jasmine 1 or jasmine 2. Seems like the smart way to go. |
Hey @BrianGenisio, do you plan on running with this? |
Sure. I can do that! Will look at it Monday. On Thu, Nov 26, 2015 at 9:02 AM Justin Searls notifications@github.com
|
Still needs some work, and I need to handle the whole Jasmine 1.x vs 2.x difference... but here is my first pass: https://www.npmjs.com/package/testdouble-jasmine I'm trying to figure out if I should register the matchers for the user (like the Thoughts? |
I like the way that testdouble-chai does it. But it's probably not a big deal since I don't anticipate having a slew of plugins. (Why not expose both? ) All I really care about is that you don't have a hard dependency on td.js As for smoothing over the API between 1 & 2, I wrote this a long time ago: https://www.npmjs.com/package/jasmine-matcher-wrapper
|
Good points. I've changed the API and now you can Internally, it figures out if it is using the Jasmine 1.x or 2.x style, and wraps it (if necessary, using your The tests validate against Jasmine 1.x or 2.x as well as the Feeling pretty good about it now: |
That's great! Send a PR to update our docs/ about it!
|
I realize that this library is platform agnostic, but I wonder if anyone has any experience getting this library to play nicely with Jasmine's expectation engine? Sorry in advance if this is a bit off-topic. Im not sure where else to ask it.
If I have a simple spec which validates that something was called:
Then Jasmine reports: "SPEC HAS NO EXPECTATIONS" and dumps an error to the console. It is very distracting.
I'd like to get Jasmine to see this
verify
call as an expectation.Any thoughts on how to accomplish this?
The text was updated successfully, but these errors were encountered: