Comments (14)
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}));
from testdouble.js.
seems legit. How would you want to incorporate this is an adaptable way to
the repo?
For instance, jasmine1, jasmine2, chai, all have separate custom matcher
APIs, and we don't want to add a dependency to any of them.
Maybe testdouble.addMatcherTo(jasmine, 'jasmine2')
? Can't think of
something clean and tidy that isn't too presumptive
On Mon, Oct 26, 2015 at 8:30 AM Brian Genisio [email protected]
wrote:
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}));
—
Reply to this email directly or view it on GitHub
#41 (comment)
.
from testdouble.js.
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?
from testdouble.js.
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.
from testdouble.js.
@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
from testdouble.js.
All this time and I never knew that every then
was silently being wrapped in a matcher!
from testdouble.js.
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! :)
from testdouble.js.
& 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.
from testdouble.js.
Hey @BrianGenisio, do you plan on running with this?
from testdouble.js.
Sure. I can do that! Will look at it Monday.
On Thu, Nov 26, 2015 at 9:02 AM Justin Searls [email protected]
wrote:
Hey @BrianGenisio https://github.com/BrianGenisio, do you plan on
running with this?—
Reply to this email directly or view it on GitHub
#41 (comment)
.
from testdouble.js.
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 jasmine-chai
pattern) or just publish the matcher and let the user decide where/when to register them. I chose the auto register for the first pass, but I'm not confident it is idiomatic for Jasmine.
Thoughts?
from testdouble.js.
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
On Feb 18, 2016, at 5:13 PM, Brian Genisio [email protected] wrote:
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 jasmine-chai pattern) or just publish the matcher and let the user decide where/when to register them. I chose the auto register for the first pass, but I'm not confident it is idiomatic for Jasmine.
Thoughts?
—
Reply to this email directly or view it on GitHub.
from testdouble.js.
Good points. I've changed the API and now you can get()
the matcher and use them however you want, or you can use()
the matcher, which registers them globally.
Internally, it figures out if it is using the Jasmine 1.x or 2.x style, and wraps it (if necessary, using your jasmine-matcher-wrapper
) and registers it using the mechanism in the library.
The tests validate against Jasmine 1.x or 2.x as well as the get()
or use()
method.
Feeling pretty good about it now:
https://www.npmjs.com/package/testdouble-jasmine
from testdouble.js.
That's great! Send a PR to update our docs/ about it!
On Feb 18, 2016, at 9:37 PM, Brian Genisio [email protected] wrote:
Good points. I've changed the API and now you can get() the matcher and use them however you want, or you can use() the matcher, which registers them globally.
Internally, it figures out if it is using the Jasmine 1.x or 2.x style, and wraps it (if necessary, using your jasmine-matcher-wrapper) and registers it using the mechanism in the library.
The tests validate against Jasmine 1.x or 2.x as well as the get() or use() method.
Feeling pretty good about it now:
https://www.npmjs.com/package/testdouble-jasmine—
Reply to this email directly or view it on GitHub.
from testdouble.js.
Related Issues (20)
- Trying to use testdouble in @web/test-runner fails with error about quibble HOT 1
- ES module replacement changed in Node 18.6 HOT 5
- Using testdouble esm loader with ts-node/esm loader on mocha leads to errors (Node 18.6.0) HOT 24
- function identity is different for modules that are not replaced with testdouble when testdouble is replacing other ESM modules HOT 10
- Importing a mocked ESM module dynamically will throw an error in node 16.17.0 HOT 3
- td.replace support for constructors? HOT 2
- td.replaceEsm() but mocking a global in that module only HOT 2
- Consider relaxing `thenReject` to accept types other than `Error` HOT 2
- How to call-through original function? HOT 1
- Incompatibility with node v20.0.0 HOT 2
- Add docs for using `testdouble` when we have to use another loader (ie `ts-node/esm`) HOT 8
- Where is changelog for 3.19.0 HOT 2
- Get list of mocked modules HOT 7
- Feature request: reset specific module(s) HOT 6
- replaceEsm behaviour HOT 1
- replaceEsm breaks in node20 when other loaders are used HOT 3
- `td.imitate` produces `undefined` for object keys of type `Accessor`
- `td.replaceEsm` does not work when specifier is resolved via loader HOT 1
- Feature request: `td.func().reset()` (reset spy/stub state)
- Suite test:esm fails under Node 21 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testdouble.js.